-
Notifications
You must be signed in to change notification settings - Fork 2
/
reset_demo_tasks.py
84 lines (84 loc) · 4.67 KB
/
reset_demo_tasks.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from app.models import *
from app.routes import *
# active trapgroups (probably want something on a permanent loop)
survey = db.session.query(Survey).get(1874)
for trapgroup in survey.trapgroups:
trapgroup.active = True
db.session.commit()
# Normal cluster tasks
for task_id in [3755]:
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
cluster.labels = []
db.session.commit()
# sub - species
for task_id in [3758]:
task = db.session.query(Task).get(task_id)
parent_label = db.session.query(Label).get(task.tagging_level)
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
cluster.labels = [parent_label]
labelgroups = db.session.query(Labelgroup).join(Detection).join(Image).filter(Image.clusters.contains(cluster)).filter(Labelgroup.task_id==task_id).all()
for labelgroup in labelgroups:
labelgroup.labels = [parent_label]
db.session.commit()
# AI check
for task_id in [3760]:
elephant = db.session.query(Label).filter(Label.task_id==task_id).filter(Laberl.description=='elephant').first()
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
cluster.labels = [elephant]
db.session.commit()
# info tagging
for task_id in [3762]:
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
cluster.tags = []
db.session.commit()
# Bounding
for task_id in [3763,3765]:
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
labelgroups = db.session.query(Labelgroup).join(Detection).join(Image).filter(Image.clusters.contains(cluster)).filter(Labelgroup.task_id==task_id).all()
for labelgroup in labelgroups:
labelgroup.labels = cluster.labels
labelgroup.examined = False
db.session.commit()
# intra-cluster ID
for task_id in [3766]:
clusters = db.session.query(Cluster).filter(Cluster.timestamp>=datetime.utcnow()-timedelta(hours=2)).filter(Cluster.task_id==task_id).filter(Cluster.examined==True).all()
for cluster in clusters:
cluster.examined = False
individuals = db.session.query(Individual).join(Task,Individual.tasks).filter(Task.id==task_id).filter(Individual.user_id!=1).all()
for individual in individuals:
individual.detections = []
individual.tags = []
individual.tasks = []
indSimilarities = db.session.query(IndSimilarity).filter(or_(IndSimilarity.individual_1==individual.id,IndSimilarity.individual_2==individual.id)).all()
for indSimilarity in indSimilarities:
db.session.delete(indSimilarity)
db.session.delete(individual)
db.session.commit()
# inter-cluster ID
for task_id in [3767]:
#combinations & unidentifiable
inactive_individuals = db.session.query(Individual).join(Task,Individual.tasks).filter(Task.id==task_id).filter(Individual.active==False).distinct().all()
for individual2 in inactive_individuals:
individual1s = db.session.query(Individual).join(Detection,Individual.detections).join(Task,Individual.tasks).filter(Task.id==task_id).filter(Detection.id.in_([r.id for r in individual2.detections])).filter(Individual.id!=individual2.id).distinct().all()
for individual1 in individual1s:
handleIndividualUndo(None,individual1,individual2,task_id)
#rejections
rejections = db.session.query(IndSimilarity).join(Individual,IndSimilarity.individual_1==Individual.id).join(Task,Individual.tasks).filter(IndSimilarity.score==-2000).filter(Task.id==task_id).distinct().all()
for rejection in rejections:
rejection.score = rejection.old_score
#skips
skips = db.session.query(IndSimilarity).join(Individual,IndSimilarity.individual_1==Individual.id).join(Task,Individual.tasks).filter(IndSimilarity.skipped==True).filter(Task.id==task_id).distinct().all()
for skip in skips:
skip.skipped = False
#dissociate - just dont
db.session.commit()