-
-
Notifications
You must be signed in to change notification settings - Fork 302
Updated metadata cherry-pick and management commands for learning activity and duration defaults #3408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rtibbles
merged 17 commits into
learningequality:hotfixes
from
rtibbles:cherry_pick_that_data
Jun 9, 2022
Merged
Updated metadata cherry-pick and management commands for learning activity and duration defaults #3408
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b02d45c
Bump pillow from 8.2.0 to 8.3.2
dependabot[bot] 5f7775e
Bump django from 3.2.4 to 3.2.5
dependabot[bot] 76cdf6d
Update le-utils with release containing new completion criteria schema
bjester 5341ea4
Update dependencies
bjester 8e868d6
Bump django from 3.2.5 to 3.2.13
dependabot[bot] 1fa2d28
Delete unused Exercise model.
rtibbles 75486ce
Delete unused permissions, tasks, and models.
rtibbles 2ba683a
Add metadata labels to contentnode model.
rtibbles b051b44
Remove unused views.
rtibbles d962552
Add duration to File model
bjester 5d6711a
Do a direct lift from unstable to ensure exact migrations.
rtibbles eb07b75
Set default learning activity on creation if not already set.
rtibbles 1764838
Add management command to update default learning activities.
rtibbles 30c025c
Add ffmpeg back into Dockerfile dependencies.
rtibbles 1b3b38e
Management command to set duration on file objects.
rtibbles a8b8bb5
Try different structure for stalling query
bjester 5c9fb87
Pipe file to ffprobe to avoid temporary file.
rtibbles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,13 @@ | ||
| from le_utils.constants import content_kinds | ||
| from le_utils.constants.labels import learning_activities | ||
|
|
||
|
|
||
| kind_activity_map = { | ||
| content_kinds.EXERCISE: learning_activities.PRACTICE, | ||
| content_kinds.VIDEO: learning_activities.WATCH, | ||
| content_kinds.AUDIO: learning_activities.LISTEN, | ||
| content_kinds.DOCUMENT: learning_activities.READ, | ||
| content_kinds.HTML5: learning_activities.EXPLORE, | ||
| content_kinds.H5P: learning_activities.EXPLORE, | ||
| content_kinds.SLIDESHOW: learning_activities.READ, | ||
| } |
This file contains hidden or 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
7 changes: 2 additions & 5 deletions
7
contentcuration/contentcuration/management/commands/loadconstants.py
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
contentcuration/contentcuration/management/commands/set_default_learning_activities.py
This file contains hidden or 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,37 @@ | ||
| import logging as logmodule | ||
| import time | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from contentcuration.constants.contentnode import kind_activity_map | ||
| from contentcuration.models import ContentNode | ||
|
|
||
| logmodule.basicConfig(level=logmodule.INFO) | ||
| logging = logmodule.getLogger('command') | ||
|
|
||
|
|
||
| CHUNKSIZE = 10000 | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
|
|
||
| def handle(self, *args, **options): | ||
| start = time.time() | ||
|
|
||
| for kind, activity in kind_activity_map.items(): | ||
| kind_start = time.time() | ||
| map_to_set = { | ||
| activity: True | ||
| } | ||
|
|
||
| null_learning_activities = ContentNode.objects.filter(kind=kind, learning_activities__isnull=True).values_list("id", flat=True) | ||
|
|
||
| logging.info("Setting default learning activities for kind: {}".format(kind)) | ||
|
|
||
| while null_learning_activities.exists(): | ||
| updated_count = ContentNode.objects.filter(id__in=null_learning_activities[0:CHUNKSIZE]).update(learning_activities=map_to_set) | ||
| logging.info("Updated {} content nodes of kind {} with learning activity {}".format(updated_count, kind, activity)) | ||
|
|
||
| logging.info("Finished setting default learning activities for kind: {} in {} seconds".format(kind, time.time() - kind_start)) | ||
|
|
||
| logging.info('Finished setting all null learning activities in {} seconds'.format(time.time() - start)) |
72 changes: 72 additions & 0 deletions
72
contentcuration/contentcuration/management/commands/set_file_duration.py
This file contains hidden or 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,72 @@ | ||
| import logging as logmodule | ||
| import subprocess | ||
| import time | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from contentcuration.models import File | ||
| from contentcuration.models import MEDIA_PRESETS | ||
|
|
||
| logmodule.basicConfig(level=logmodule.INFO) | ||
| logging = logmodule.getLogger('command') | ||
|
|
||
|
|
||
| CHUNKSIZE = 10000 | ||
|
|
||
|
|
||
| def extract_duration_of_media(f_in): | ||
| result = subprocess.check_output( | ||
| [ | ||
| "ffprobe", | ||
| "-v", | ||
| "error", | ||
| "-show_entries", | ||
| "format=duration", | ||
| "-of", | ||
| "default=noprint_wrappers=1:nokey=1", | ||
| "-loglevel", | ||
| "panic", | ||
| "-" | ||
| ], | ||
| stdin=f_in, | ||
| ) | ||
| return int(float(result.decode("utf-8").strip())) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
|
|
||
| def handle(self, *args, **options): | ||
| start = time.time() | ||
|
|
||
| logging.info("Setting default duration for media presets: {}".format(MEDIA_PRESETS)) | ||
|
|
||
| excluded_files = set() | ||
|
|
||
| null_duration = File.objects.filter(preset_id__in=MEDIA_PRESETS, duration__isnull=True) | ||
| null_duration_count = null_duration.count() | ||
| updated_count = 0 | ||
|
|
||
| i = 0 | ||
|
|
||
| while i < null_duration_count: | ||
| for file in null_duration[i:i + CHUNKSIZE]: | ||
| if file.file_on_disk.name in excluded_files: | ||
| continue | ||
| file.refresh_from_db() | ||
| if file.duration is not None: | ||
| continue | ||
| try: | ||
| with file.file_on_disk.open() as f: | ||
| duration = extract_duration_of_media(f) | ||
| if duration: | ||
| updated_count += File.objects.filter(checksum=file.checksum, preset_id__in=MEDIA_PRESETS).update(duration=duration) | ||
| except FileNotFoundError: | ||
| logging.warning("File {} not found".format(file)) | ||
| excluded_files.add(file.file_on_disk.name) | ||
| except subprocess.CalledProcessError: | ||
| logging.warning("File {} could not be read for duration".format(file)) | ||
| excluded_files.add(file.file_on_disk.name) | ||
|
|
||
| i += CHUNKSIZE | ||
|
|
||
| logging.info('Finished setting all null duration for {} files in {} seconds'.format(updated_count, time.time() - start)) | ||
16 changes: 16 additions & 0 deletions
16
contentcuration/contentcuration/migrations/0131_auto_20210707_2326.py
This file contains hidden or 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,16 @@ | ||
| # Generated by Django 3.2.4 on 2021-07-07 23:26 | ||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('contentcuration', '0130_auto_20210706_2005'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.DeleteModel( | ||
| name='ChannelResourceSize', | ||
| ), | ||
| ] |
16 changes: 16 additions & 0 deletions
16
contentcuration/contentcuration/migrations/0132_auto_20210708_0011.py
This file contains hidden or 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,16 @@ | ||
| # Generated by Django 3.2.4 on 2021-07-08 00:11 | ||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('contentcuration', '0131_auto_20210707_2326'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.DeleteModel( | ||
| name='Exercise', | ||
| ), | ||
| ] |
22 changes: 22 additions & 0 deletions
22
contentcuration/contentcuration/migrations/0133_auto_20220124_2149.py
This file contains hidden or 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,22 @@ | ||
| # Generated by Django 3.2.5 on 2022-01-24 21:49 | ||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('contentcuration', '0132_auto_20210708_0011'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='file', | ||
| name='duration', | ||
| field=models.IntegerField(blank=True, null=True), | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name='file', | ||
| constraint=models.CheckConstraint(check=models.Q(models.Q(('duration__gt', 0), ('preset__in', ['audio', 'high_res_video', 'low_res_video'])), ('duration__isnull', True), _connector='OR'), name='file_media_duration_int'), | ||
| ), | ||
| ] |
34 changes: 34 additions & 0 deletions
34
contentcuration/contentcuration/migrations/0134_alter_contentkind_kind.py
This file contains hidden or 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,34 @@ | ||
| # Generated by Django 3.2.5 on 2022-02-23 18:42 | ||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("contentcuration", "0133_auto_20220124_2149"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="contentkind", | ||
| name="kind", | ||
| field=models.CharField( | ||
| choices=[ | ||
| ("topic", "Topic"), | ||
| ("video", "Video"), | ||
| ("audio", "Audio"), | ||
| ("exercise", "Exercise"), | ||
| ("document", "Document"), | ||
| ("html5", "HTML5 App"), | ||
| ("slideshow", "Slideshow"), | ||
| ("h5p", "H5P"), | ||
| ("zim", "Zim"), | ||
| ("quiz", "Quiz"), | ||
| ], | ||
| max_length=200, | ||
| primary_key=True, | ||
| serialize=False, | ||
| ), | ||
| ), | ||
| ] |
43 changes: 43 additions & 0 deletions
43
contentcuration/contentcuration/migrations/0135_add_metadata_labels.py
This file contains hidden or 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,43 @@ | ||
| # Generated by Django 3.2.5 on 2022-02-25 00:23 | ||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('contentcuration', '0134_alter_contentkind_kind'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='accessibility_labels', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='categories', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='grade_levels', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='learner_needs', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='learning_activities', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='contentnode', | ||
| name='resource_types', | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.