Skip to content

Commit 5074656

Browse files
committedMar 13, 2025
Script to tidy up some bad data sync'd from monitor #3473
1 parent 944fba3 commit 5074656

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
load('../../../utils/audit.js');
2+
load('../../../utils/reports.js');
3+
const adminUserId = 'system';
4+
let project=db.project.findOne({projectId:'f4a0642b-49b7-4ec3-9be5-e7e65a25cb78'});
5+
let dataSets=project.custom.dataSets;
6+
print(project.custom.dataSets.length);
7+
let deleteCount =0;
8+
function removeDataSet(dataSets, badSurveyUuid, goodDataSetId, deleteStarted) {
9+
for (let i=0; i<dataSets.length; i++) {
10+
let dataSet=dataSets[i];
11+
if (dataSet.surveyId) {
12+
if (dataSet.surveyId.survey_metadata.survey_details.uuid == badSurveyUuid) {
13+
14+
if (dataSet.progress != 'planned') {
15+
if (deleteStarted && dataSet.progress == 'started') {
16+
if (dataSet.dataSetId != goodDataSetId) {
17+
print("Deleting dataset: " + dataSet.dataSetId + " for survey: " + badSurveyUuid+ " with name: " + dataSet.name + " in started state");
18+
deleteActivity(dataSet.activityId, adminUserId);
19+
// remove the dataset from the array
20+
dataSets.splice(i, 1);
21+
deleteCount++;
22+
return dataSets;
23+
}
24+
}
25+
else {
26+
print("Warning dataset is not in planned state: " + dataSet.dataSetId + ", "+dataSet.name);
27+
}
28+
29+
30+
} else {
31+
print("Deleting dataset: " + dataSet.dataSetId + " for survey: " + badSurveyUuid+ " with name: " + dataSet.name+ " in planned state");
32+
33+
// remove the dataset from the array
34+
dataSets.splice(i, 1);
35+
deleteCount++;
36+
return dataSets;
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
function deleteAndUpdate(badSurveyId, goodDatasetId, deleteStarted) {
44+
deleteCount = 0;
45+
let dataSets = project.custom.dataSets;
46+
47+
while (dataSets) {
48+
dataSets = removeDataSet(dataSets, badSurveyUuid, goodDatasetId, deleteStarted);
49+
}
50+
print("Deleted " + deleteCount+ " datasets with survey uuid " + badSurveyUuid);
51+
print(project.custom.dataSets.length);
52+
53+
db.project.replaceOne({projectId:project.projectId}, project);
54+
audit(project, project.projectId, 'au.org.ala.ecodata.Project', 'system', project.projectId);
55+
}
56+
57+
// Cover - enhanced
58+
let badSurveyUuid = '3d4940ef-2eca-4a87-b2d2-4b228dbd499e';
59+
deleteAndUpdate(badSurveyUuid);
60+
61+
// Photopoints
62+
badSurveyUuid = '9b5360ce-5b4e-478f-b006-0292e22870ba';
63+
goodDataSetId = '40982ac4-8464-4d1a-a1da-9dc7c1ae979d';
64+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
65+
66+
// FLoristics
67+
badSurveyUuid = '7a635ab4-c871-4a4b-8b69-94c5d83a56d2';
68+
goodDataSetId = 'f57b2b34-bdc7-4e91-b28f-5e231f63cad5';
69+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
70+
71+
// Floristics
72+
badSurveyUuid = '955ebed3-bc05-4353-abcb-bf1c3e1c98db';
73+
goodDataSetId = 'a941dbe7-9a0f-4f84-a3ce-f51d0c39f8f9';
74+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
75+
76+
// Floristics
77+
badSurveyUuid = '6a970b22-4521-469c-ac79-a83ef7c2d0d1';
78+
goodDataSetId = 'c4bdd5ad-6f92-494a-99d6-bb3dc887b733';
79+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
80+
81+
// Floristics
82+
badSurveyUuid = '1ed22901-469a-4ee6-985e-dbec17780cb1';
83+
goodDataSetId = '582afd5a-567e-4616-b658-29f5a597f1e9';
84+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
85+
86+
// Floristics
87+
badSurveyUuid = '852382f0-1526-4c7e-bb02-7edf6c369840';
88+
goodDataSetId = 'f4b6b130-fa9a-4a38-8408-14f3b934c496';
89+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
90+
91+
// Floristics
92+
badSurveyUuid = 'b6f3f4db-9e83-44db-aac1-859b7dae06d6';
93+
goodDataSetId = '04a6397b-1443-49fe-83d6-354f51fe7021';
94+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
95+
96+
// Floristics
97+
badSurveyUuid = '5ddc8adf-ecbb-4221-ac52-d75ca20e7442';
98+
goodDataSetId = '6b3ab834-4037-4ab8-9dd4-b376682144f4';
99+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
100+
101+
badSurveyUuid = '9d4defe3-c1fb-43b9-9594-06c00ecb6729';
102+
deleteAndUpdate(badSurveyUuid);
103+
104+
badSurveyUuid = 'be49fe0d-8d97-4a62-9ec5-c45f171d7c8e';
105+
deleteAndUpdate(badSurveyUuid);
106+
107+
// Floristics
108+
badSurveyUuid = 'd1ab3343-761d-4a6e-b47e-0c3001d72f5a';
109+
goodDataSetId = 'c0d1bc94-f965-4f3e-977f-c671fbcbe1f1';
110+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
111+

‎src/main/scripts/utils/reports.js

+24
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,28 @@ function createReportForProject(reportDetails, project, adminUserId) {
282282
let savedActivity = db.activity.findOne({activityId:activity.activityId});
283283
audit(savedActivity, savedActivity.activityId, 'au.org.ala.ecodata.Activity', adminUserId, project.projectId);
284284

285+
}
286+
287+
288+
function deleteActivity(activityId, adminUserId) {
289+
290+
291+
let activity = db.activity.findOne({activityId: activityId});
292+
print("deleting activity: "+activityId+" "+activity.description);
293+
if (activity) {
294+
activity.status = 'deleted';
295+
296+
db.activity.replaceOne({activityId: activityId}, activity);
297+
audit(activity, activity.activityId, 'au.org.ala.ecodata.Activity', adminUserId, activity.projectId);
298+
299+
let outputs = db.output.find({activityId: activityId});
300+
while (outputs.hasNext()) {
301+
let output = outputs.next();
302+
output.status = 'deleted';
303+
print("deleting output: "+output.outputId+" "+output.name);
304+
db.output.replaceOne({outputId: output.outputId}, output);
305+
audit(output, output.outputId, 'au.org.ala.ecodata.Output', adminUserId, activity.projectId);
306+
}
307+
}
308+
285309
}

0 commit comments

Comments
 (0)