Просмотр исходного кода

Added scoring system and removed variable opacity

Denis Merigoux лет назад: 9
Родитель
Сommit
59e9dfc869
2 измененных файлов с 14 добавлено и 8 удалено
  1. 1 1
      counter/templates/homeTemplate.html
  2. 13 7
      counter/views.py

+ 1 - 1
counter/templates/homeTemplate.html

88
 	<div class="row">
88
 	<div class="row">
89
 		{% for counter in counters %} {% if chooseCounter or not counter.id == myCounter.id %}
89
 		{% for counter in counters %} {% if chooseCounter or not counter.id == myCounter.id %}
90
 		<div class="col-md-3 col-sm-4 col-lg-2">
90
 		<div class="col-md-3 col-sm-4 col-lg-2">
91
-			<div class="panel panel-{{counter.CSSclass}}" style="opacity:{{counter.opacity}}">
91
+			<div class="panel panel-{{counter.CSSclass}}">
92
 				<div class="panel-heading">
92
 				<div class="panel-heading">
93
 					<form action="{% url 'like' %}" method="POST" name="like{{counter.id}}">
93
 					<form action="{% url 'like' %}" method="POST" name="like{{counter.id}}">
94
 						{% csrf_token %}
94
 						{% csrf_token %}

+ 13 - 7
counter/views.py

69
             counter.lastReset.delta = no_seum_delta
69
             counter.lastReset.delta = no_seum_delta
70
             counter.lastReset.noSeum = True
70
             counter.lastReset.noSeum = True
71
             counter.CSSclass = "warning"
71
             counter.CSSclass = "warning"
72
+            counter.likeCount = -1
72
         else:  # This person already had the seum
73
         else:  # This person already had the seum
73
             counter.lastReset = lastReset[0]
74
             counter.lastReset = lastReset[0]
74
             # To display the last seum we have to know if it is self-inflicted
75
             # To display the last seum we have to know if it is self-inflicted
98
                               (24 * 3600))
99
                               (24 * 3600))
99
             # Defining CSS attributes for the counter
100
             # Defining CSS attributes for the counter
100
             counter.CSSclass = "default"
101
             counter.CSSclass = "default"
101
-            counter.opacity = 0.4 + 0.6 * \
102
-                math.exp(-(counter.lastReset.delta.total_seconds()) /
103
-                         (7 * 24 * 3600))
104
             # Computing the total number of likes for this counter
102
             # Computing the total number of likes for this counter
105
             counter.likeCount = Like.objects.filter(
103
             counter.likeCount = Like.objects.filter(
106
                 reset=counter.lastReset).count()
104
                 reset=counter.lastReset).count()
111
             counter.lastReset.delta, locale='fr', threshold=1)
109
             counter.lastReset.delta, locale='fr', threshold=1)
112
         counter.isHidden = "hidden"
110
         counter.isHidden = "hidden"
113
 
111
 
114
-    # Eventually we sort the counters to display the most recent resets top
115
-    counters = sorted(counters, key=lambda t: t.lastReset.delta)
112
+    # Now we sort the counters according to a reddit-like ranking formula
113
+    # We take into account the number of likes of a reset and its recentness
114
+    # The log on the score will give increased value to the first likes
115
+    # The negative exp for the time with a characteristic time of 1 day will
116
+    # cause that after 1 day the « recentness score drops from 1 to 0.36
117
+    # The counters with no seum have a like count of -1 by convention
118
+    counters = sorted(counters, key=lambda t: - (
119
+                      math.log(t.likeCount + 2) *
120
+                      math.exp(-(t.lastReset.delta.total_seconds()) /
121
+                                (24 * 3600))))
116
 
122
 
117
     # Column graph
123
     # Column graph
118
     if (len(lastResets) == 0):
124
     if (len(lastResets) == 0):
360
             if reset.selfSeum:
366
             if reset.selfSeum:
361
                 reset.Seum = {'v': 0, 'f': reset.reason}
367
                 reset.Seum = {'v': 0, 'f': reset.reason}
362
             else:
368
             else:
363
-                reset.Seum = {'v': 0, 'f': 'De ' + reset.who.trigramme + ' : ' +
364
-                              reset.reason}
369
+                reset.Seum = {'v': 0, 'f': 'De ' +
370
+                              reset.who.trigramme + ' : ' + reset.reason}
365
         # Drawing the graph
371
         # Drawing the graph
366
         data = ModelDataSource(
372
         data = ModelDataSource(
367
             resets, fields=['timestamp', 'Seum'])
373
             resets, fields=['timestamp', 'Seum'])