@@ -17,6 +17,7 @@ class Command(BaseCommand):
17
17
"question_no" ,
18
18
"topic" ,
19
19
"question" ,
20
+ "no_mark_options" ,
20
21
"criteria" ,
21
22
"clarifications" ,
22
23
"how_marked" ,
@@ -59,6 +60,18 @@ def add_arguments(self, parser):
59
60
"--column_list" , action = "store" , help = "file with list of column names"
60
61
)
61
62
63
+ parser .add_argument (
64
+ "--delete_old_no_mark_options" ,
65
+ action = "store_true" ,
66
+ help = "remove old options with zero marks" ,
67
+ )
68
+
69
+ parser .add_argument (
70
+ "--delete_options" ,
71
+ action = "store_true" ,
72
+ help = "remove all options and recreate" ,
73
+ )
74
+
62
75
def get_column_names (self , ** kwargs ):
63
76
column_list = kwargs .get ("column_list" , None )
64
77
column_list = settings .BASE_DIR / "data" / column_list
@@ -140,7 +153,6 @@ def handle(self, quiet: bool = False, *args, **kwargs):
140
153
df = df .dropna (axis = "index" , how = "all" )
141
154
drop_cols = [
142
155
"Climate Justice/Adaptation Tag" ,
143
- "Drop down box options for no mark awarded (internal)" ,
144
156
"Is this question or criteria changing?" ,
145
157
"Change proposed" ,
146
158
"New Criteria" ,
@@ -154,10 +166,14 @@ def handle(self, quiet: bool = False, *args, **kwargs):
154
166
for col in drop_cols :
155
167
if col in df .columns :
156
168
df = df .drop (col , axis = 1 )
157
- df = df .iloc [:, :14 ]
169
+ # df = df.iloc[:, :15 ]
158
170
159
171
columns = list (self .column_names )
160
- options = len (df .columns ) - len (self .column_names ) + 1
172
+
173
+ if "Drop down box options for no mark awarded (internal)" not in df .columns :
174
+ columns .remove ("no_mark_options" )
175
+
176
+ options = len (df .columns ) - len (columns ) + 1
161
177
for i in range (1 , options ):
162
178
columns .append (f"option_{ i } " )
163
179
@@ -254,37 +270,70 @@ def handle(self, quiet: bool = False, *args, **kwargs):
254
270
if kwargs ["text_only" ] or kwargs ["weighting_only" ]:
255
271
continue
256
272
273
+ if kwargs ["delete_old_no_mark_options" ]:
274
+ Option .objects .filter (question = q , score = 0 ).delete ()
275
+
276
+ if kwargs ["delete_options" ]:
277
+ Option .objects .filter (question = q ).delete ()
278
+
279
+ if row .get ("no_mark_options" ) is not None :
280
+ no_mark_options = row ["no_mark_options" ].splitlines ()
281
+ else :
282
+ no_mark_options = []
283
+
284
+ no_mark_options .extend (
285
+ [
286
+ "No Penalty Mark" ,
287
+ "No evidence found" ,
288
+ "Evidence does not meet criteria" ,
289
+ "No response from FOI" ,
290
+ ]
291
+ )
292
+
257
293
if q .question_type in ["select_one" , "tiered" , "multiple_choice" ]:
258
- o , c = Option .objects .update_or_create (
259
- question = q ,
260
- description = "None" ,
261
- defaults = {"score" : 0 , "ordering" : 100 },
262
- )
294
+ if not no_mark_options :
295
+ o , c = Option .objects .update_or_create (
296
+ question = q ,
297
+ description = "None" ,
298
+ defaults = {"score" : 0 , "ordering" : 100 },
299
+ )
300
+ no_mark_seen = 0
263
301
for i in range (1 , options ):
264
- desc = row [f"option_{ i } " ]
302
+ desc = str (row [f"option_{ i } " ]).strip ()
303
+ if pd .isna (desc ) or desc == "" :
304
+ continue
265
305
score = 1
266
306
ordering = i
267
307
if q .question_type == "tiered" :
268
- score = i
269
- if not pd .isna (desc ):
270
- o , c = Option .objects .update_or_create (
271
- question = q ,
272
- description = desc ,
273
- defaults = {"score" : score , "ordering" : ordering },
274
- )
275
- elif q .question_type == "yes_no" :
276
- for desc in ["Yes" , "No" ]:
277
- ordering = 1
278
- score = 1
279
- if desc == "No" :
308
+ score = i - no_mark_seen
309
+ if desc in no_mark_options :
310
+ no_mark_seen = no_mark_seen + 1
280
311
score = 0
281
- ordering = 2
282
312
o , c = Option .objects .update_or_create (
283
313
question = q ,
284
314
description = desc ,
285
315
defaults = {"score" : score , "ordering" : ordering },
286
316
)
317
+ elif q .question_type == "yes_no" :
318
+ o , c = Option .objects .update_or_create (
319
+ question = q ,
320
+ description = "Yes" ,
321
+ defaults = {"score" : 1 , "ordering" : 1 },
322
+ )
323
+ if no_mark_options :
324
+ for option in no_mark_options :
325
+ o , c = Option .objects .update_or_create (
326
+ question = q ,
327
+ description = option ,
328
+ defaults = {"score" : 0 , "ordering" : 100 },
329
+ )
330
+ else :
331
+ o , c = Option .objects .update_or_create (
332
+ question = q ,
333
+ description = "No" ,
334
+ defaults = {"score" : 0 , "ordering" : 2 },
335
+ )
287
336
288
337
for col , group in q_groups .items ():
289
- if row [col ] == "Yes" :
338
+ if row [col ] in [ "Yes" , "Y" , "All" ] :
290
339
q .questiongroup .add (group )
0 commit comments