Index: filters/rndsortbydate.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/filters/rndsortbydate.py |
@@ -0,0 +1,12 @@ |
+ |
saroyanm
2016/01/22 11:58:14
no need to use short form of the words and abbrevi
saroyanm
2016/01/22 11:58:14
please use "hg rename" when renaming the files, so
juliandoucette
2016/01/25 16:19:55
Done.
juliandoucette
2016/01/25 16:19:55
Done.
|
+import random |
+from datetime import datetime |
+ |
+def rndsortbydate(value, basedate="1970-01-01", column=0): |
+ base =datetime.strptime(basedate, "%Y-%m-%d") |
+ def randdiff(entry): |
+ date = datetime.strptime(entry[column], "%Y-%m-%d") |
+ diff = (date - base).days |
+ return diff * 0.2 + random.randrange(diff) * 0.8 |
+ return sorted(value, key=randdiff) |
+ |