remove zero duration annotations parameter added in mashupbytag.
authorcavaliet
Fri, 14 Dec 2012 18:56:00 +0100
changeset 1031 04f8cf193221
parent 1030 581c7906ebb4
child 1032 726f2cf3f020
remove zero duration annotations parameter added in mashupbytag.
src/ldt/ldt/ldt_utils/views/json.py
--- a/src/ldt/ldt/ldt_utils/views/json.py	Fri Dec 14 17:48:30 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py	Fri Dec 14 18:56:00 2012 +0100
@@ -93,6 +93,13 @@
     escape_bool = False
     if escape_str:
         escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower())
+    # do we remove annotations from mashup if the have duration=0 ? (yes by default)
+    remove_zero_dur_str = request.REQUEST.get("removezeroduration")
+    remove_zero_dur = True
+    logging.debug("CC 1 " + str(remove_zero_dur))
+    if remove_zero_dur_str:
+        remove_zero_dur = {'true': True, 'false': False, "0": False, "1": True}.get(remove_zero_dur_str.lower())
+    logging.debug("CC 2 " + str(remove_zero_dur))
     
     # We search
     s = request.REQUEST.get("tag")
@@ -160,15 +167,16 @@
                 for res in highest_weighted:
                     cur_in = res["start_ts"]
                     cur_out = cur_in + res["duration"]
-                    if tc_in<=cur_in and cur_out<=tc_out:
+                    if tc_in<=cur_in and cur_out<=tc_out and ((not remove_zero_dur) or (remove_zero_dur and res["duration"]>0.0)):
                         #mashup_list["items"].append(res["iri_id"] + ", " + res["element_id"] + ", " + str(res["start_ts"]) + ", " + str(res["duration"]) + ", " + str(res["weight"]))
                         mashup_list["items"].append(res["element_id"])
             else:
                 # no particular sorting
                 for res in results:
                     cur_in = float(res["start_ts"])
-                    cur_out = cur_in + float(res["duration"])
-                    if tc_in<=cur_in and cur_out<=tc_out:
+                    dur = float(res["duration"])
+                    cur_out = cur_in + dur
+                    if tc_in<=cur_in and cur_out<=tc_out and ((not remove_zero_dur) or (remove_zero_dur and dur>0.0)):
                         mashup_list["items"].append(res["element_id"])
             mashup_dict["lists"].append(mashup_list)