-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,701 additions
and
1,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ typing-extensions = "*" | |
drf-excel = "*" | ||
|
||
[requires] | ||
python_version = "3" | ||
python_version = "3" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
from datetime import timedelta | ||
import logging | ||
|
||
from ohq.models import Profile, Course, Question | ||
from ohq.statistics import ( | ||
user_calculate_questions_asked, | ||
user_calculate_questions_answered, | ||
user_calculate_time_helped, | ||
user_calculate_time_helping, | ||
user_calculate_students_helped, | ||
) | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument("--hist", action="store_true", help="Calculate all historic statistics") | ||
|
||
def calculate_statistics(self, profiles, courses, earliest_date): | ||
yesterday = timezone.datetime.today().date() - timezone.timedelta(days=1) | ||
active_users_today = set() | ||
|
||
for course in courses: | ||
logger.debug("course here is", course) | ||
if earliest_date: | ||
date = earliest_date | ||
else: | ||
course_questions = Question.objects.filter(queue__course=course) | ||
date = ( | ||
timezone.template_localtime( | ||
course_questions.earliest("time_asked").time_asked | ||
).date() | ||
if course_questions | ||
else yesterday | ||
) | ||
|
||
course_questions = Question.objects.filter(queue__course=course, time_asked__gte=date) | ||
for q in course_questions: | ||
active_users_today.add(q.asked_by) | ||
active_users_today.add(q.responded_to_by) | ||
|
||
for profile in profiles: | ||
if profile.user in active_users_today: | ||
user_calculate_questions_asked(profile.user) | ||
user_calculate_questions_answered(profile.user) | ||
user_calculate_time_helped(profile.user) | ||
user_calculate_time_helping(profile.user) | ||
user_calculate_students_helped(profile.user) | ||
|
||
|
||
def handle(self, *args, **kwargs): | ||
if kwargs["hist"]: | ||
courses = Course.objects.all() | ||
profiles = Profile.objects.all() | ||
earliest_date = None | ||
else: | ||
courses = Course.objects.filter(archived=False) | ||
profiles = Profile.objects.all() | ||
earliest_date = timezone.now().date() - timedelta(days=1) | ||
|
||
self.calculate_statistics(profiles, courses, earliest_date) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 3.1.7 on 2024-03-26 02:26 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('ohq', '0019_auto_20211114_1800'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserStatistic', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('metric', models.CharField(choices=[('TOTAL_QUESTIONS_ASKED', 'Total questions asked'), ('TOTAL_QUESTIONS_ANSWERED', 'Total questions answered'), ('TOTAL_TIME_BEING_HELPED', 'Total time being helped'), ('TOTAL_TIME_HELPING', 'Total time helping'), ('TOTAL_STUDENTS_HELPED', 'Total students helped')], max_length=256)), | ||
('value', models.DecimalField(decimal_places=8, max_digits=16)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name='userstatistic', | ||
constraint=models.UniqueConstraint(fields=('user', 'metric'), name='unique_user_statistic'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"@types/node": "^20.11.30" | ||
} | ||
} |
Oops, something went wrong.