-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnormalize_doppelgaenger.py
More file actions
executable file
·51 lines (41 loc) · 1.86 KB
/
normalize_doppelgaenger.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#==============================================================================
# This script eliminates doppelgaenger in the visible data.
# It links everything connected to this speaker to the "highest"
# database entry of the speaker
#
# This script is meant for manual use.
#
# Use this script if you added data in a "doppelgaenger_of_id" field of a
# speaker and want this to be applied to all the datasets belonging to the
# speaker
#
# This script fixes relations in:
# * Moves the Talk_Persons Relationship to the right speaker
# * Adds the Statistics_raw data to the right speaker
# * Adds the Statistics_Speaker data to the right speaker
#==============================================================================
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "subtitleStatus.settings")
import django
django.setup()
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.core.exceptions import ObjectDoesNotExist
from www.models import Statistics_Raw_Data, Speaker, Statistics_Speaker, Talk_Persons
# Get all Speakers with doppelgaenger_of non empty
all_doppelgaenger = Speaker.objects.all().exclude(doppelgaenger_of = None)
print(all_doppelgaenger.count())
for this_d in all_doppelgaenger:
print("Id: " + str(this_d.id))
# Substitute in Statistics_raw
my_statistics_raw = Statistics_Raw_Data.objects.filter(speaker = this_d)
my_statistics_raw.update(speaker = this_d.doppelgaenger_of)
# Substitute in Statistics_Speaker
my_statistics_speaker = Statistics_Speaker.objects.filter(speaker = this_d)
my_statistics_speaker.update(speaker = this_d.doppelgaenger_of)
# Substitute in Talk_Persons
my_talk_persons = Talk_Persons.objects.filter(speaker = this_d)
my_talk_persons.update(speaker = this_d.doppelgaenger_of)
print("Done!")