Commit 8f48302affe7aa184d20cfaf0c7dfc782e031bb2

Authored by Bartłomiej Nitoń
1 parent 338da08b

Fixes to payments counting algorithm.

accounts/admin.py
... ... @@ -27,22 +27,27 @@ from models import AnonymousUserProfile, RealizedLemma, GroupSettings, \
27 27 RealizedPhraseology, RealizedPhraseologyBinding, \
28 28 RealizedSemantics, UserSettings, UserStats
29 29  
30   -class RealizedLemmaAdmin(admin.ModelAdmin):
31   - search_fields = ('lemma__entry',)
  30 +class RealizedLemmaAdmin(admin.ModelAdmin):
  31 + exclude = ('lemma',)
32 32 list_filter = ('status', 'paid', 'lemma__vocabulary', 'bonus', 'counted',)
33   -
34   -class RealizedPhraseologyAdmin(admin.ModelAdmin):
  33 + readonly_fields = ('date',)
35 34 search_fields = ('lemma__entry',)
  35 +
  36 +class RealizedPhraseologyAdmin(admin.ModelAdmin):
  37 + exclude = ('lemma',)
36 38 list_filter = ('status', 'paid', 'lemma__vocabulary', 'bonus', 'counted',)
  39 + readonly_fields = ('date',)
  40 + search_fields = ('lemma__entry',)
37 41  
38 42 class RealizedSemanticsAdmin(admin.ModelAdmin):
  43 + list_filter = ('status', 'bonus',)
39 44 search_fields = ('entry__name',)
40   - list_filter = ('status', 'bonus', )
41 45  
42 46 class UserStatsAdmin(admin.ModelAdmin):
43 47 exclude = ('lemma_real_history', 'phraseology_real_history',
44 48 'bind_phraseology_frames_history')
45   -
  49 +
  50 +admin.site.register(AnonymousUserProfile)
46 51 admin.site.register(UserSettings)
47 52 admin.site.register(UserStats, UserStatsAdmin)
48 53 admin.site.register(RealizedLemma, RealizedLemmaAdmin)
... ... @@ -50,6 +55,5 @@ admin.site.register(RealizedPhraseology, RealizedPhraseologyAdmin)
50 55 admin.site.register(RealizedSemantics, RealizedSemanticsAdmin)
51 56 admin.site.register(GroupSettings)
52 57 admin.site.register(RealizedPhraseologyBinding)
53   -admin.site.register(AnonymousUserProfile)
54 58  
55 59 admin.site.register(Session)
... ...
dictionary/ajax_lemma_status.py
... ... @@ -128,6 +128,14 @@ def lemma_status_change(request, status_id, lemma_id):
128 128 new_status = Lemma_Status.objects.get(id=status_id)
129 129 except:
130 130 pass
  131 +
  132 + if new_status and new_status == lemma_obj.status:
  133 + raise AjaxError('already changed')
  134 +
  135 + if(new_status and
  136 + not new_status == lemma_obj.status.abort_status and
  137 + not lemma_obj.status.next_statuses.filter(pk=new_status.pk).exists()):
  138 + raise AjaxError('wrong change')
131 139  
132 140 actual_semantic_frames = SemanticFrame.objects.none()
133 141 next_status = False
... ... @@ -174,8 +182,16 @@ def lemma_status_change(request, status_id, lemma_id):
174 182 update_lemma_stats_conf(lemma_obj, lemma_obj.owner, request.user, new_status,
175 183 checked_frame_value, corrected_frame_value, bonus_factor)
176 184 changed = True
  185 + # zmiana statusu na w obrobce
  186 + elif(new_status and
  187 + (lemma_obj.status.type.sym_name == 'ready' or lemma_obj.status.type.sym_name == 'checked') and
  188 + lemma_obj.status.abort_status == new_status):
  189 + remove_lexicography_payments(lemma_obj)
  190 + changed = True
  191 +
177 192 # pobieranie hasla do obrobki frazeologicznej
178   - elif(lemma_obj.status.type.sym_name == 'checked' and
  193 + elif(new_status and
  194 + lemma_obj.status.type.sym_name == 'checked' and
179 195 edit_vocabulary and new_status.type.sym_name == 'edit_f'
180 196 and next_status):
181 197 lemma_obj.phraseologist = request.user
... ... @@ -210,7 +226,8 @@ def lemma_status_change(request, status_id, lemma_id):
210 226 changed = True
211 227  
212 228 # pobieranie hasla do obrobki semantycznej
213   - elif(lemma_obj.status.type.sym_name == 'checked_f' and
  229 + elif(new_status and
  230 + lemma_obj.status.type.sym_name == 'checked_f' and
214 231 edit_vocabulary and new_status.type.sym_name == 'edit_s'
215 232 and next_status):
216 233 lemma_obj.semanticist = request.user
... ... @@ -226,7 +243,7 @@ def lemma_status_change(request, status_id, lemma_id):
226 243 elif(new_status and new_status.type.sym_name == 'ready_s'
227 244 and next_status):
228 245 ### naliczanie oplat za gotowosc semantyczna
229   - frame_value = 8
  246 + frame_value = 8.0
230 247 update_sem_stats_ready_s(lemma_obj.entry_obj, actual_semantic_frames,
231 248 lemma_obj.semanticist, new_status, frame_value)
232 249 add_new_frames_to_phraseologic_propositions(lemma_obj)
... ... @@ -242,6 +259,12 @@ def lemma_status_change(request, status_id, lemma_id):
242 259 lemma_obj.semanticist, request.user, new_status,
243 260 checked_frame_value, corrected_frame_value, bonus)
244 261 add_new_frames_to_phraseologic_propositions(lemma_obj)
  262 + changed = True
  263 + # zmiana statusu na w obrobce semantycznej
  264 + elif(new_status and
  265 + (lemma_obj.status.type.sym_name == 'ready_s' or lemma_obj.status.type.sym_name == 'checked_s') and
  266 + lemma_obj.status.abort_status == new_status):
  267 + remove_semantic_payments(lemma_obj.entry_obj)
245 268 changed = True
246 269  
247 270 # jak oznaczamy status jako "do usuniecia", to czyscimy oplaty za haslo
... ... @@ -275,7 +298,8 @@ def lemma_status_change(request, status_id, lemma_id):
275 298 'message' : message,
276 299 'new_status_type': new_status_type,
277 300 'next_status' : next_status}
278   -
  301 +
  302 +############# marking as 'to erase' #################
279 303 def erase_payments(lemma):
280 304 RealizedLemma.objects.filter(lemma__entry_obj=lemma.entry_obj).delete()
281 305 RealizedPhraseology.objects.filter(lemma__entry_obj=lemma.entry_obj).delete()
... ... @@ -283,149 +307,85 @@ def erase_payments(lemma):
283 307  
284 308 ############## lexicography #######################
285 309 def update_lemma_stats_ready(lemma, lex, status, flat_frames_value):
286   - """Update user stats about properly created frames."""
287   - ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready')
288   - q_ready_statuses = []
289   - for ready_status in ready_statuses.all():
290   - q_ready_statuses.append(Q(status=ready_status))
291   - ready_lemmas = RealizedLemma.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(lemma__entry=lemma.entry).order_by('-date')
292   - ncounted_ready_lemmas = ready_lemmas.filter(counted=False)
293   - # sprawdz czy dane haslo nie zostalo juz podliczone
294   - if ncounted_ready_lemmas.exists() or not ready_lemmas.exists():
295   - lex_dict = {'made_frames': 0,
296   - 'cash': 0.0}
297   - for frame in lemma.frames.all():
298   - flat_frames = float(frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'])
299   - lex_dict['made_frames'] += flat_frames
300   - lex_dict['cash'] += flat_frames_value*flat_frames
301   -
302   - # leksykograf nie został jeszcze oplacony za dane haslo, wiec zmien wartosc
303   - if not ready_lemmas.exists():
304   - lex_real_lemma = RealizedLemma(lemma=lemma, cash=lex_dict['cash'],
305   - made_frames=lex_dict['made_frames'],
306   - paid=False, status=status, bonus=False,
307   - counted=False)
308   - lex_real_lemma.save()
309   - lex.user_stats.lemma_real_history.add(lex_real_lemma)
310   - else:
311   - to_update = RealizedLemma.objects.get(pk=ready_lemmas[0].pk)
312   - to_update.lemma = lemma
313   - to_update.cash = lex_dict['cash']
314   - to_update.made_frames = lex_dict['made_frames']
315   - to_update.status = status
316   - to_update.save()
317   -
318   - # leksykograf moze sie tez zmienic
319   - old_lex = to_update.user_stats.all()[0].user # UWAGA: leksykograf tez moze sie zmienic
320   - if old_lex != lex:
321   - old_lex.user_stats.lemma_real_history.remove(to_update)
322   - lex.user_stats.lemma_real_history.add(to_update)
  310 + lex_dict = {'made_frames': 0,
  311 + 'cash': 0.0}
  312 + for frame in lemma.frames.all():
  313 + flat_frames = float(frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'])
  314 + lex_dict['made_frames'] += flat_frames
  315 + lex_dict['cash'] += flat_frames_value*flat_frames
  316 +
  317 + lex_real_lemma = RealizedLemma(lemma=lemma, cash=lex_dict['cash'],
  318 + made_frames=lex_dict['made_frames'],
  319 + paid=False, status=status, bonus=False,
  320 + counted=False)
  321 + lex_real_lemma.save()
  322 + lex.user_stats.lemma_real_history.add(lex_real_lemma)
323 323  
324 324 def update_lemma_stats_conf(lemma, lex, superlex, status,
325 325 checked_frame_value, corrected_frame_value, bonus_factor):
326   - """Update user stats about properly created frames."""
327 326 ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready')
328   - q_ready_statuses = []
329   - for ready_status in ready_statuses.all():
330   - q_ready_statuses.append(Q(status=ready_status))
  327 + q_ready_statuses = [Q(status=ready_status) for ready_status in ready_statuses.all()]
331 328  
332   - checked_statuses = Lemma_Status.objects.filter(type__sym_name='checked')
333   - q_checked_statuses = []
334   - for checked_status in checked_statuses.all():
335   - q_checked_statuses.append(Q(status=checked_status))
336   -
337   - checked_lemmas = RealizedLemma.objects.filter(reduce(operator.or_, q_checked_statuses)).filter(lemma__entry=lemma.entry,
338   - bonus=False).order_by('-date')
339   - ncounted_checked_lemmas = checked_lemmas.filter(counted=False)
  329 + all_realized_lemmas = RealizedLemma.objects.filter(reduce(operator.or_, q_ready_statuses))
  330 + ready_lemma = all_realized_lemmas.get(lemma__entry_obj=lemma.entry_obj).lemma
  331 + lex_dict = {'same_frames': 0,
  332 + 'wrong_frames': 0,
  333 + 'cash': 0.0}
  334 + superlex_dict = {'same_frames': [],
  335 + 'redo_frames': [],
  336 + 'cash': 0.0}
  337 + q_same_frames = []
  338 + for frame in ready_lemma.frames.all():
  339 + flat_frames = float(frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'])
  340 + try:
  341 + same_frame = lemma.frames.get(text_rep=frame.text_rep)
  342 +
  343 + superlex_dict['same_frames'].append(frame)
  344 + superlex_dict['cash'] += checked_frame_value
  345 +
  346 + lex_dict['same_frames'] += flat_frames
  347 + bonus = flat_frames * bonus_factor*flat_frames**(1.0/3.0)
  348 + lex_dict['cash'] += bonus
  349 +
  350 + q_same_frames.append(Q(text_rep=same_frame.text_rep))
  351 + except Frame.DoesNotExist:
  352 + lex_dict['wrong_frames'] += flat_frames
  353 + continue
340 354  
341   - # sprawdz czy dane haslo nie zsotalo juz podliczone
342   - if ncounted_checked_lemmas.exists() or not checked_lemmas.exists():
343   - ready_lemmas = RealizedLemma.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(lemma__entry=lemma.entry).order_by('-date').all()
344   - ready_lemma = ready_lemmas[len(ready_lemmas)-1].lemma
345   - lex_dict = {'same_frames': 0,
346   - 'wrong_frames': 0,
347   - 'cash': 0.0}
348   - superlex_dict = {'same_frames': [],
349   - 'redo_frames': [],
350   - 'cash': 0.0}
351   - q_same_frames = []
352   - for frame in ready_lemma.frames.all():
353   - flat_frames = float(frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'])
354   - try:
355   - same_frame = lemma.frames.get(text_rep=frame.text_rep)
356   -
357   - superlex_dict['same_frames'].append(frame)
358   - superlex_dict['cash'] += checked_frame_value
359   -
360   - lex_dict['same_frames'] += flat_frames
361   - bonus = flat_frames * bonus_factor*flat_frames**(1.0/3.0)
362   - lex_dict['cash'] += bonus
363   -
364   - q_same_frames.append(Q(text_rep=same_frame.text_rep))
365   - except Frame.DoesNotExist:
366   - lex_dict['wrong_frames'] += flat_frames
367   - continue
  355 + new_frames = lemma.frames
  356 + if len(q_same_frames) > 0:
  357 + new_frames = new_frames.exclude(reduce(operator.or_, q_same_frames))
  358 + superlex_dict['redo_frames'] = new_frames.all()
  359 + for frame in superlex_dict['redo_frames']:
  360 + superlex_dict['cash'] += corrected_frame_value
  361 + # superleksykograf nie zostal jeszcze oplacony za dane haslo, zmien wartosc
  362 +
  363 + superlex_real_lemma = RealizedLemma(lemma=lemma, cash=superlex_dict['cash'],
  364 + corr_frames=len(superlex_dict['redo_frames']),
  365 + ncorr_frames=len(superlex_dict['same_frames']),
  366 + paid=False, status=status, bonus=False,
  367 + counted=False)
  368 + superlex_real_lemma.save()
  369 + superlex.user_stats.lemma_real_history.add(superlex_real_lemma)
  370 +
  371 + # hasla pochodzace z cesara maja cash = 0.0 i nie nalezy ich bonusować
  372 + try:
  373 + RealizedLemma.objects.get(lemma__entry=lemma.entry,
  374 + status__type__sym_name='ready',
  375 + bonus=False, cash=0.0, paid=True,
  376 + counted=True)
  377 + except RealizedLemma.DoesNotExist:
  378 + lex_real_lemma = RealizedLemma(lemma=lemma,
  379 + cash=lex_dict['cash'],
  380 + prop_frames=lex_dict['same_frames'],
  381 + wrong_frames=lex_dict['wrong_frames'],
  382 + paid=False, status=status,
  383 + bonus=True, counted=False)
  384 + lex_real_lemma.save()
  385 + lex.user_stats.lemma_real_history.add(lex_real_lemma)
368 386  
369   - new_frames = lemma.frames
370   - if len(q_same_frames) > 0:
371   - new_frames = new_frames.exclude(reduce(operator.or_, q_same_frames))
372   - superlex_dict['redo_frames'] = new_frames.all()
373   - for frame in superlex_dict['redo_frames']:
374   - superlex_dict['cash'] += corrected_frame_value
375   - # superleksykograf nie zostal jeszcze oplacony za dane haslo, zmien wartosc
376   - if not checked_lemmas.exists():
377   - superlex_real_lemma = RealizedLemma(lemma=lemma, cash=superlex_dict['cash'],
378   - corr_frames=len(superlex_dict['redo_frames']),
379   - ncorr_frames=len(superlex_dict['same_frames']),
380   - paid=False, status=status, bonus=False,
381   - counted=False)
382   - superlex_real_lemma.save()
383   - superlex.user_stats.lemma_real_history.add(superlex_real_lemma)
384   - else:
385   - to_update = RealizedLemma.objects.get(pk=checked_lemmas[0].pk)
386   - to_update.lemma = lemma
387   - to_update.cash = superlex_dict['cash']
388   - to_update.corr_frames = len(superlex_dict['redo_frames'])
389   - to_update.ncorr_frames = len(superlex_dict['same_frames'])
390   - to_update.status = status
391   - to_update.save()
392   -
393   - # superleksykograf tylko klika wiec moze sie zmienic
394   - old_superlex = to_update.user_stats.all()[0].user # UWAGA: leksykograf tez moze sie zmienic
395   - if old_superlex != superlex:
396   - old_superlex.user_stats.lemma_real_history.remove(to_update)
397   - superlex.user_stats.lemma_real_history.add(to_update)
398   - # hasla pochodzace z clarinu maja cash = 0.0 i nie nalezy ich bonusować
399   - try:
400   - RealizedLemma.objects.get(lemma__entry=lemma.entry,
401   - status__type__sym_name='ready',
402   - bonus=False, cash=0.0, paid=True,
403   - counted=True)
404   - except RealizedLemma.DoesNotExist:
405   - try: # zmienianie bonusu
406   - lex_real_lemma = RealizedLemma.objects.get(lemma__entry=lemma.entry,
407   - status__type__sym_name=status.type.sym_name,
408   - bonus=True)
409   - if not lex_real_lemma.counted:
410   - lex_real_lemma.lemma = lemma
411   - lex_real_lemma.cash = lex_dict['cash']
412   - lex_real_lemma.prop_frames = lex_dict['same_frames']
413   - lex_real_lemma.wrong_frames = lex_dict['wrong_frames']
414   - lex_real_lemma.status = status
415   - lex_real_lemma.save()
416   - old_lex = lex_real_lemma.user_stats.all()[0].user # UWAGA: leksykograf tez moze sie zmienic
417   - if old_lex != lex:
418   - old_lex.user_stats.lemma_real_history.remove(lex_real_lemma)
419   - lex.user_stats.lemma_real_history.add(lex_real_lemma)
420   - except RealizedLemma.DoesNotExist:
421   - lex_real_lemma = RealizedLemma(lemma=lemma,
422   - cash=lex_dict['cash'],
423   - prop_frames=lex_dict['same_frames'],
424   - wrong_frames=lex_dict['wrong_frames'],
425   - paid=False, status=status,
426   - bonus=True, counted=False)
427   - lex_real_lemma.save()
428   - lex.user_stats.lemma_real_history.add(lex_real_lemma)
  387 +def remove_lexicography_payments(lemma):
  388 + RealizedLemma.objects.filter(lemma__entry_obj=lemma.entry_obj).delete()
429 389  
430 390 ######################## phraseology #############################
431 391 def add_new_frames_to_phraseologic_propositions(lemma):
... ... @@ -441,215 +401,107 @@ def add_new_frames_to_phraseologic_propositions(lemma):
441 401  
442 402 def update_lemma_stats_ready_f(lemma, phraseologist, status,
443 403 new_phraseologic_frame_value, proposed_phraseologic_frame_value):
444   - """Update user stats about added phraseologic frames."""
445   - ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready_f')
446   - q_ready_statuses = []
447   - for ready_status in ready_statuses.all():
448   - q_ready_statuses.append(Q(status=ready_status))
449   - ready_lemmas = RealizedPhraseology.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(lemma__entry=lemma.entry,
450   - lemma__entry_obj__pos=lemma.entry_obj.pos).order_by('-date')
451   - ncounted_ready_lemmas = ready_lemmas.filter(counted=False)
452   - # sprawdz czy dane haslo nie zostalo juz podliczone
453   - if ncounted_ready_lemmas.exists() or not ready_lemmas.exists():
454   - phraseologist_dict = {'new_frames': 0,
455   - 'reused_frames': 0,
456   - 'cash': 0.0}
457   - for frame in lemma.frames.filter(phraseologic=True).all():
458   - if frame_structure_exists(frames=lemma.entry_obj.phraseologic_propositions.all(),
459   - searched_frame=frame):
460   - phraseologist_dict['reused_frames'] += 1
461   - phraseologist_dict['cash'] += proposed_phraseologic_frame_value
462   - else:
463   - phraseologist_dict['new_frames'] += 1
464   - phraseologist_dict['cash'] += new_phraseologic_frame_value
465   -
466   - # leksykograf nie został jeszcze oplacony za dane haslo, wiec zmien wartosc
467   - if not ready_lemmas.exists():
468   - phrase_real_lemma = RealizedPhraseology(lemma=lemma,
469   - cash=phraseologist_dict['cash'],
470   - new_frames=phraseologist_dict['new_frames'],
471   - reused_frames=phraseologist_dict['reused_frames'],
472   - paid=False,
473   - status=status,
474   - bonus=False,
475   - counted=False)
476   - phrase_real_lemma.save()
477   - phraseologist.user_stats.phraseology_real_history.add(phrase_real_lemma)
  404 + phraseologist_dict = {'new_frames': 0,
  405 + 'reused_frames': 0,
  406 + 'cash': 0.0}
  407 + for frame in lemma.frames.filter(phraseologic=True).all():
  408 + if frame_structure_exists(frames=lemma.entry_obj.phraseologic_propositions.all(),
  409 + searched_frame=frame):
  410 + phraseologist_dict['reused_frames'] += 1
  411 + phraseologist_dict['cash'] += proposed_phraseologic_frame_value
478 412 else:
479   - to_update = RealizedPhraseology.objects.get(pk=ready_lemmas[0].pk)
480   - to_update.lemma = lemma
481   - to_update.cash = phraseologist_dict['cash']
482   - to_update.new_frames = phraseologist_dict['new_frames']
483   - to_update.reused_frames = phraseologist_dict['reused_frames']
484   - to_update.status = status
485   - to_update.save()
486   -
487   - # frazeolog moze sie tez zmienic
488   - old_phraseologist = to_update.user_stats.all()[0].user # UWAGA: frazeolog tez moze sie zmienic
489   - if old_phraseologist != phraseologist:
490   - old_phraseologist.user_stats.phraseology_real_history.remove(to_update)
491   - phraseologist.user_stats.phraseology_real_history.add(to_update)
  413 + phraseologist_dict['new_frames'] += 1
  414 + phraseologist_dict['cash'] += new_phraseologic_frame_value
  415 +
  416 + phrase_real_lemma = RealizedPhraseology(lemma=lemma,
  417 + cash=phraseologist_dict['cash'],
  418 + new_frames=phraseologist_dict['new_frames'],
  419 + reused_frames=phraseologist_dict['reused_frames'],
  420 + paid=False,
  421 + status=status,
  422 + bonus=False,
  423 + counted=False)
  424 + phrase_real_lemma.save()
  425 + phraseologist.user_stats.phraseology_real_history.add(phrase_real_lemma)
492 426  
493 427 def update_lemma_stats_conf_f(lemma, phraseologist, superphraseologist, status,
494 428 checked_frame_value, corrected_frame_value, bonus):
495   - """Update user stats about properly created phraseologic frames."""
496 429 ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready_f')
497   - q_ready_statuses = []
498   - for ready_status in ready_statuses.all():
499   - q_ready_statuses.append(Q(status=ready_status))
  430 + q_ready_statuses = [Q(status=ready_status) for ready_status in ready_statuses.all()]
500 431  
501   - checked_statuses = Lemma_Status.objects.filter(type__sym_name='checked_f')
502   - q_checked_statuses = []
503   - for checked_status in checked_statuses.all():
504   - q_checked_statuses.append(Q(status=checked_status))
505   -
506   - checked_lemmas = RealizedPhraseology.objects.filter(reduce(operator.or_, q_checked_statuses)).filter(lemma__entry_obj=lemma.entry_obj,
507   - bonus=False).order_by('-date')
508   - ncounted_checked_lemmas = checked_lemmas.filter(counted=False)
  432 + ready_lemmas = RealizedPhraseology.objects.filter(reduce(operator.or_, q_ready_statuses))
  433 + ready_lemma = ready_lemmas.get(lemma__entry_obj=lemma.entry_obj).lemma
  434 + phraseologist_dict = {'same_frames': 0,
  435 + 'wrong_frames': 0,
  436 + 'cash': 0.0}
  437 + superphraseologist_dict = {'same_frames': [],
  438 + 'redo_frames': [],
  439 + 'cash': 0.0}
  440 + q_same_frames = []
  441 + for frame in ready_lemma.frames.filter(phraseologic=True).all():
  442 + try:
  443 + same_frame = lemma.frames.filter(phraseologic=True).get(text_rep=frame.text_rep)
  444 +
  445 + superphraseologist_dict['same_frames'].append(frame)
  446 + superphraseologist_dict['cash'] += checked_frame_value
  447 +
  448 + phraseologist_dict['same_frames'] += 1
  449 + phraseologist_dict['cash'] += bonus
  450 +
  451 + q_same_frames.append(Q(text_rep=same_frame.text_rep))
  452 + except Frame.DoesNotExist:
  453 + phraseologist_dict['wrong_frames'] += 1
  454 + continue
509 455  
510   - # sprawdz czy dane haslo nie zsotalo juz podliczone
511   - if ncounted_checked_lemmas.exists() or not checked_lemmas.exists():
512   - ready_lemmas = RealizedPhraseology.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(lemma__entry_obj=lemma.entry_obj).order_by('-date').all()
513   - ready_lemma = ready_lemmas[len(ready_lemmas)-1].lemma
514   - phraseologist_dict = {'same_frames': 0,
515   - 'wrong_frames': 0,
516   - 'cash': 0.0}
517   - superphraseologist_dict = {'same_frames': [],
518   - 'redo_frames': [],
519   - 'cash': 0.0}
520   - q_same_frames = []
521   - for frame in ready_lemma.frames.filter(phraseologic=True).all():
522   - #flat_frames = float(frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'])
523   - try:
524   - same_frame = lemma.frames.filter(phraseologic=True).get(text_rep=frame.text_rep)
525   -
526   - superphraseologist_dict['same_frames'].append(frame)
527   - superphraseologist_dict['cash'] += checked_frame_value
528   -
529   - phraseologist_dict['same_frames'] += 1
530   - phraseologist_dict['cash'] += bonus
531   -
532   - q_same_frames.append(Q(text_rep=same_frame.text_rep))
533   - except Frame.DoesNotExist:
534   - phraseologist_dict['wrong_frames'] += 1
535   - continue
  456 + new_frames = lemma.frames.filter(phraseologic=True)
  457 + if len(q_same_frames) > 0:
  458 + new_frames = new_frames.exclude(reduce(operator.or_, q_same_frames))
  459 + superphraseologist_dict['redo_frames'] = new_frames.all()
  460 + for frame in superphraseologist_dict['redo_frames']:
  461 + superphraseologist_dict['cash'] += corrected_frame_value
  462 +
  463 + superphraseologist_real_lemma = RealizedPhraseology(lemma=lemma,
  464 + cash=superphraseologist_dict['cash'],
  465 + corr_frames=len(superphraseologist_dict['redo_frames']),
  466 + ncorr_frames=len(superphraseologist_dict['same_frames']),
  467 + paid=False,
  468 + status=status,
  469 + bonus=False,
  470 + counted=False)
  471 + superphraseologist_real_lemma.save()
  472 + superphraseologist.user_stats.phraseology_real_history.add(superphraseologist_real_lemma)
536 473  
537   - new_frames = lemma.frames.filter(phraseologic=True)
538   - if len(q_same_frames) > 0:
539   - new_frames = new_frames.exclude(reduce(operator.or_, q_same_frames))
540   - superphraseologist_dict['redo_frames'] = new_frames.all()
541   - for frame in superphraseologist_dict['redo_frames']:
542   - superphraseologist_dict['cash'] += corrected_frame_value
543   - # superleksykograf nie zostal jeszcze oplacony za dane haslo, zmien wartosc
544   - if not checked_lemmas.exists():
545   - superphraseologist_real_lemma = RealizedPhraseology(lemma=lemma,
546   - cash=superphraseologist_dict['cash'],
547   - corr_frames=len(superphraseologist_dict['redo_frames']),
548   - ncorr_frames=len(superphraseologist_dict['same_frames']),
549   - paid=False,
550   - status=status,
551   - bonus=False,
552   - counted=False)
553   - superphraseologist_real_lemma.save()
554   - superphraseologist.user_stats.phraseology_real_history.add(superphraseologist_real_lemma)
555   - else:
556   - to_update = RealizedPhraseology.objects.get(pk=checked_lemmas[0].pk)
557   - to_update.lemma = lemma
558   - to_update.cash = superphraseologist_dict['cash']
559   - to_update.corr_frames = len(superphraseologist_dict['redo_frames'])
560   - to_update.ncorr_frames = len(superphraseologist_dict['same_frames'])
561   - to_update.status = status
562   - to_update.save()
563   -
564   - # superfrazeolog tylko klika wiec moze sie zmienic
565   - old_superphraseologist = to_update.user_stats.all()[0].user # UWAGA: frazeolog tez moze sie zmienic
566   - if old_superphraseologist != superphraseologist:
567   - old_superphraseologist.user_stats.phraseology_real_history.remove(to_update)
568   - superphraseologist.user_stats.phraseology_real_history.add(to_update)
569   - # hasla pochodzace z clarinu maja cash = 0.0 i nie nalezy ich bonusować
570   - try:
571   - RealizedPhraseology.objects.get(lemma__entry_obj=lemma.entry_obj,
572   - status__type__sym_name='ready_f',
573   - bonus=False, cash=0.0, paid=True,
574   - counted=True)
575   - except RealizedPhraseology.DoesNotExist:
576   - try: # zmienianie bonusu
577   - phraseologist_real_lemma = RealizedPhraseology.objects.get(lemma__entry_obj=lemma.entry_obj,
578   - status__type__sym_name=status.type.sym_name,
579   - bonus=True)
580   - if not phraseologist_real_lemma.counted:
581   - phraseologist_real_lemma.lemma = lemma
582   - phraseologist_real_lemma.cash = phraseologist_dict['cash']
583   - phraseologist_real_lemma.prop_frames = phraseologist_dict['same_frames']
584   - phraseologist_real_lemma.wrong_frames = phraseologist_dict['wrong_frames']
585   - phraseologist_real_lemma.status = status
586   - phraseologist_real_lemma.save()
587   - old_phraseologist = phraseologist_real_lemma.user_stats.all()[0].user # UWAGA: frazeolog tez moze sie zmienic
588   - if old_phraseologist != phraseologist:
589   - old_phraseologist.user_stats.phraseology_real_history.remove(phraseologist_real_lemma)
590   - phraseologist.user_stats.phraseology_real_history.add(phraseologist_real_lemma)
591   - except RealizedPhraseology.DoesNotExist:
592   - phraseologist_real_lemma = RealizedPhraseology(lemma=lemma,
593   - cash=phraseologist_dict['cash'],
594   - prop_frames=phraseologist_dict['same_frames'],
595   - wrong_frames=phraseologist_dict['wrong_frames'],
596   - paid=False, status=status,
597   - bonus=True, counted=False)
598   - phraseologist_real_lemma.save()
599   - phraseologist.user_stats.phraseology_real_history.add(phraseologist_real_lemma)
  474 + phraseologist_real_lemma = RealizedPhraseology(lemma=lemma,
  475 + cash=phraseologist_dict['cash'],
  476 + prop_frames=phraseologist_dict['same_frames'],
  477 + wrong_frames=phraseologist_dict['wrong_frames'],
  478 + paid=False,
  479 + status=status,
  480 + bonus=True,
  481 + counted=False)
  482 + phraseologist_real_lemma.save()
  483 + phraseologist.user_stats.phraseology_real_history.add(phraseologist_real_lemma)
600 484  
601 485 ####################### semantics #############################
602 486 def update_sem_stats_ready_s(entry, semantic_frames, semanticist, status, frame_value):
603   - """Update user stats about created semantic frames."""
604   - ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready_s')
605   - q_ready_statuses = []
606   - for ready_status in ready_statuses.all():
607   - q_ready_statuses.append(Q(status=ready_status))
608   - ready_semantics = RealizedSemantics.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(entry=entry).order_by('-date')
609 487 actual_frames_count = semantic_frames.count()
610 488 sem_dict = {'made_frames': actual_frames_count,
611 489 'cash': frame_value*float(actual_frames_count)}
612   - # sprawdz czy dane haslo nie zostalo juz podliczone
613   - if not ready_semantics.exists():
614   - # semantyk nie został jeszcze oplacony za dane haslo, wiec utworz
615   - realized_semantics = RealizedSemantics(entry=entry, cash=sem_dict['cash'],
616   - made_frames=sem_dict['made_frames'],
617   - status=status, bonus=False)
618   - realized_semantics.save()
619   - realized_semantics.frames.add(*semantic_frames.all())
620   - semanticist.user_stats.semantics_real_history.add(realized_semantics)
621   - else:
622   - to_update = RealizedSemantics.objects.get(pk=ready_semantics[0].pk)
623   - to_update.cash = sem_dict['cash']
624   - to_update.made_frames = sem_dict['made_frames']
625   - to_update.frames.clear()
626   - to_update.frames.add(*semantic_frames.all())
627   - to_update.status = status
628   - to_update.save()
629   -
630   - # semantyk moze sie zmienic
631   - old_semanticist = to_update.user_stats.all()[0].user # UWAGA: semantyk tez moze sie zmienic
632   - if old_semanticist != semanticist:
633   - old_semanticist.user_stats.semantics_real_history.remove(to_update)
634   - semanticist.user_stats.semantics_real_history.add(to_update)
  490 +
  491 + realized_semantics = RealizedSemantics(entry=entry, cash=sem_dict['cash'],
  492 + made_frames=sem_dict['made_frames'],
  493 + status=status, bonus=False)
  494 + realized_semantics.save()
  495 + realized_semantics.frames.add(*semantic_frames.all())
  496 + semanticist.user_stats.semantics_real_history.add(realized_semantics)
635 497  
636 498 def update_sem_stats_conf_s(entry, semantic_frames, semanticist, supersemanticist, status,
637 499 checked_frame_value, corrected_frame_value, bonus_factor):
638   - """Update user stats about checked semantic frames."""
639 500 ready_statuses = Lemma_Status.objects.filter(type__sym_name='ready_s')
640   - q_ready_statuses = []
641   - for ready_status in ready_statuses.all():
642   - q_ready_statuses.append(Q(status=ready_status))
643   -
644   - checked_statuses = Lemma_Status.objects.filter(type__sym_name='checked_s')
645   - q_checked_statuses = []
646   - for checked_status in checked_statuses.all():
647   - q_checked_statuses.append(Q(status=checked_status))
  501 + q_ready_statuses = [Q(status=ready_status) for ready_status in ready_statuses.all()]
648 502  
649   - checked_semantics = RealizedSemantics.objects.filter(reduce(operator.or_, q_checked_statuses)).filter(entry=entry,
650   - bonus=False).order_by('-date')
651   - ready_semantics = RealizedSemantics.objects.filter(reduce(operator.or_, q_ready_statuses)).filter(entry=entry).order_by('-date')
652   - ready_sem_frames = ready_semantics[ready_semantics.count()-1].frames
  503 + ready_semantics = RealizedSemantics.objects.filter(reduce(operator.or_, q_ready_statuses))
  504 + ready_sem_frames= ready_semantics.get(entry=entry).frames
653 505 checked_sem_frames = semantic_frames
654 506 ready_to_checked_diffs = get_frames_differences(ready_sem_frames.all(), checked_sem_frames.all())
655 507 checked_to_ready_diffs = get_frames_differences(checked_sem_frames.all(), ready_sem_frames.all())
... ... @@ -660,59 +512,26 @@ def update_sem_stats_conf_s(entry, semantic_frames, semanticist, supersemanticis
660 512 'redo_frames': len(checked_to_ready_diffs['missing_frames']),
661 513 'cash': (float(len(checked_to_ready_diffs['missing_frames']))*corrected_frame_value+
662 514 float(len(ready_to_checked_diffs['matching_frames']))*checked_frame_value)}
663   -
664   - # sprawdz czy dane haslo nie zostalo juz podliczone
665   - if not checked_semantics.exists():
666   - supersem_real_semantics = RealizedSemantics(entry=entry,
667   - cash=supersem_dict['cash'],
668   - corr_frames=supersem_dict['redo_frames'],
669   - ncorr_frames=supersem_dict['same_frames'],
670   - status=status,
671   - bonus=False)
672   - supersem_real_semantics.save()
673   - supersem_real_semantics.frames.add(*semantic_frames.all())
674   - supersemanticist.user_stats.semantics_real_history.add(supersem_real_semantics)
675   - else:
676   - to_update = RealizedSemantics.objects.get(pk=checked_semantics[0].pk)
677   - to_update.cash = supersem_dict['cash']
678   - to_update.corr_frames = len(supersem_dict['redo_frames'])
679   - to_update.ncorr_frames = len(supersem_dict['same_frames'])
680   - to_update.status = status
681   - to_update.frames.clear()
682   - to_update.frames.add(*semantic_frames.all())
683   - to_update.save()
684   -
685   - # supersemantyk tylko klika wiec moze sie zmienic
686   - old_supersem = to_update.user_stats.all()[0].user
687   - if old_supersem != supersemanticist:
688   - old_supersem.user_stats.semantics_real_history.remove(to_update)
689   - supersemanticist.user_stats.semantics_real_history.add(to_update)
690   -
  515 +
  516 + supersem_real_semantics = RealizedSemantics(entry=entry,
  517 + cash=supersem_dict['cash'],
  518 + corr_frames=supersem_dict['redo_frames'],
  519 + ncorr_frames=supersem_dict['same_frames'],
  520 + status=status,
  521 + bonus=False)
  522 + supersem_real_semantics.save()
  523 + supersem_real_semantics.frames.add(*semantic_frames.all())
  524 + supersemanticist.user_stats.semantics_real_history.add(supersem_real_semantics)
691 525  
692   - try: # zmienianie bonusu
693   - sem_real_semantics = RealizedSemantics.objects.get(entry=entry,
694   - status__type__sym_name=status.type.sym_name,
695   - bonus=True)
696   - sem_real_semantics.cash = sem_dict['cash']
697   - sem_real_semantics.prop_frames = sem_dict['same_frames']
698   - sem_real_semantics.wrong_frames = sem_dict['wrong_frames']
699   - sem_real_semantics.status = status
700   - sem_real_semantics.frames.clear()
701   - sem_real_semantics.frames.add(*semantic_frames.all())
702   - sem_real_semantics.save()
  526 + sem_real_semantics = RealizedSemantics(entry=entry,
  527 + cash=sem_dict['cash'],
  528 + prop_frames=sem_dict['same_frames'],
  529 + wrong_frames=sem_dict['wrong_frames'],
  530 + status=status,
  531 + bonus=True)
  532 + sem_real_semantics.save()
  533 + sem_real_semantics.frames.add(*semantic_frames.all())
  534 + semanticist.user_stats.semantics_real_history.add(sem_real_semantics)
703 535  
704   - old_sem = sem_real_semantics.user_stats.all()[0].user
705   - if old_sem != semanticist:
706   - old_sem.user_stats.semantics_real_history.remove(sem_real_semantics)
707   - semanticist.user_stats.semantics_real_history.add(sem_real_semantics)
708   -
709   - except RealizedSemantics.DoesNotExist:
710   - sem_real_semantics = RealizedSemantics(entry=entry,
711   - cash=sem_dict['cash'],
712   - prop_frames=sem_dict['same_frames'],
713   - wrong_frames=sem_dict['wrong_frames'],
714   - status=status,
715   - bonus=True)
716   - sem_real_semantics.save()
717   - sem_real_semantics.frames.add(*semantic_frames.all())
718   - semanticist.user_stats.semantics_real_history.add(sem_real_semantics)
  536 +def remove_semantic_payments(entry):
  537 + RealizedSemantics.objects.filter(entry=entry).delete()
... ...
dictionary/static/js/lemma-view.js
... ... @@ -3495,6 +3495,16 @@ function lemma_status_change(status_id) {
3495 3495 alertUserNotAuthenticated();
3496 3496 return false;
3497 3497 }
  3498 + else if(result == 'already changed') {
  3499 + HideProgressAnimation();
  3500 + error_alert('Status już został zmieniony.');
  3501 + return false;
  3502 + }
  3503 + else if(result == 'wrong change') {
  3504 + HideProgressAnimation();
  3505 + error_alert('Nie można dokonać zmiany statusu, najpewniej został on już zmieniony.');
  3506 + return false;
  3507 + }
3498 3508 else {
3499 3509 HideProgressAnimation();
3500 3510 return true;
... ...
semantics/management/commands/add_predefined_preferences.py
... ... @@ -21,6 +21,9 @@ def create_predefined_preferences():
21 21 # ALL
22 22 all, xx = GeneralSelectivePreference.objects.get_or_create(name=u'ALL')
23 23  
  24 +
  25 + # POŁOŻENIE: miejsce-1, przestrzeń-1, obiekt-2
  26 +
24 27 # LUDZIE: osoba-1, grupa ludzi-1
25 28 ludzie_members = SelectivePreference()
26 29 ludzie_members.save()
... ... @@ -61,7 +64,7 @@ def create_predefined_preferences():
61 64 podmioty, xx = GeneralSelectivePreference.objects.get_or_create(name=u'PODMIOTY',
62 65 members=podmioty_members)
63 66  
64   - # DOBRA: jedzenie-2, mienie-1, przedmiot-1, wytwór-1
  67 + # DOBRA: jedzenie-2, mienie-1, przedmiot-1, wytwór-1 ==> JADŁO, mienie-1, przedmiot-1, wytwór-1
65 68 dobra_members = SelectivePreference()
66 69 dobra_members.save()
67 70 jedzenie_2 = LexicalUnit.objects.get(base=u'jedzenie',
... ... @@ -130,7 +133,7 @@ def create_predefined_preferences():
130 133 jadlo, xx = GeneralSelectivePreference.objects.get_or_create(name=u'JADŁO',
131 134 members=jadlo_members)
132 135  
133   - # MIEJSCE: miejsce-1, przestrzeń-1, obiekt-2
  136 + # MIEJSCE: miejsce-1, przestrzeń-1, obiekt-2 ==> lokal-1, budynek-1, rejon-1, obszar-1, państwo-1, jednostka administracyjna-1, woda-4
134 137 miejsce_members = SelectivePreference()
135 138 miejsce_members.save()
136 139 miejsce_1 = LexicalUnit.objects.get(base=u'miejsce',
... ... @@ -202,7 +205,7 @@ def create_predefined_preferences():
202 205 czynnosc, xx = GeneralSelectivePreference.objects.get_or_create(name=u'CZYNNOŚĆ',
203 206 members=czynnosc_members)
204 207  
205   - # SYTUACJA
  208 + # SYTUACJA ==> czynność-1, zdarzenie-2, okoliczność-1, ciąg zdarzeń-1
206 209 sytuacja, xx = GeneralSelectivePreference.objects.get_or_create(name=u'SYTUACJA')
207 210  
208 211 # KIEDY: CZAS, SYTUACJA
... ...
semantics/models.py
... ... @@ -60,6 +60,9 @@ class LexicalUnitExamples(models.Model):
60 60 class GeneralSelectivePreference(models.Model):
61 61 name = models.CharField(max_length=20)
62 62 members = models.ForeignKey('SelectivePreference', null=True)
  63 +
  64 + def __unicode__(self):
  65 + return u'%s' % (self.name)
63 66  
64 67 class SelectivePreferenceRelations(models.Model):
65 68 plwn_id = models.IntegerField(null=True)
... ...