Merge lp:~ricotz/slingshot/synapse-zeitgeist-2.0 into lp:~elementary-pantheon/slingshot/trunk

Proposed by Rico Tzschichholz on 2014-07-02
Status: Merged
Merged at revision: 424
Proposed branch: lp:~ricotz/slingshot/synapse-zeitgeist-2.0
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 204 lines (+49/-44)
2 files modified
lib/synapse-core/CMakeLists.txt (+1/-1)
lib/synapse-core/relevancy-backend-zg.vala (+48/-43)
To merge this branch: bzr merge lp:~ricotz/slingshot/synapse-zeitgeist-2.0
Reviewer Review Type Date Requested Status
Tom Beckmann (community) 2014-07-02 Approve on 2014-07-03
Review via email: mp+225393@code.launchpad.net

Commit message

synapse-core: Port to zeitgeist-2.0

Description of the change

synapse-core: Port to zeitgeist-2.0

To post a comment you must log in.
424. By Rico Tzschichholz on 2014-07-03

synapse-core: Port to zeitgeist-2.0

This avoids linking against two zeitgeist libraries.

Tom Beckmann (tombeckmann) wrote :

Looks great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/synapse-core/CMakeLists.txt'
--- lib/synapse-core/CMakeLists.txt 2014-06-13 21:09:06 +0000
+++ lib/synapse-core/CMakeLists.txt 2014-07-03 06:39:48 +0000
@@ -3,7 +3,7 @@
3set(CORE_LIBRARY_NAME synapse-core)3set(CORE_LIBRARY_NAME synapse-core)
4set(CORE_PKG4set(CORE_PKG
5 glib-2.05 glib-2.0
6 zeitgeist-1.06 zeitgeist-2.0
7 gio-unix-2.07 gio-unix-2.0
8 json-glib-1.08 json-glib-1.0
9 gee-0.89 gee-0.8
1010
=== modified file 'lib/synapse-core/relevancy-backend-zg.vala'
--- lib/synapse-core/relevancy-backend-zg.vala 2014-06-04 19:35:44 +0000
+++ lib/synapse-core/relevancy-backend-zg.vala 2014-07-03 06:39:48 +0000
@@ -47,19 +47,16 @@
47 zg_dsr = new Zeitgeist.DataSourceRegistry ();47 zg_dsr = new Zeitgeist.DataSourceRegistry ();
48 try48 try
49 {49 {
50 var ptr_arr = yield zg_dsr.get_data_sources (null);50 var array = yield zg_dsr.get_data_sources (null);
5151
52 for (uint i=0; i < ptr_arr.len; i++)52 array.foreach ((ds) => {
53 {53 if (ds.unique_id == "com.zeitgeist-project,datahub,gio-launch-listener"
54 unowned Zeitgeist.DataSource ds;54 && ds.enabled)
55 ds = (Zeitgeist.DataSource) ptr_arr.index (i);
56 if (ds.get_unique_id () == "com.zeitgeist-project,datahub,gio-launch-listener"
57 && ds.is_enabled ())
58 {55 {
59 has_datahub_gio_module = true;56 has_datahub_gio_module = true;
60 break;57 return;
61 }58 }
62 }59 });
63 }60 }
64 catch (Error err)61 catch (Error err)
65 {62 {
@@ -79,25 +76,25 @@
79 Idle.add (load_application_relevancies.callback, Priority.LOW);76 Idle.add (load_application_relevancies.callback, Priority.LOW);
80 yield;77 yield;
8178
82 int64 end = Zeitgeist.Timestamp.now ();79 int64 end = new DateTime.now_local ().to_unix () * 1000;
83 int64 start = end - Zeitgeist.Timestamp.WEEK * 4;80 int64 start = end - Zeitgeist.Timestamp.WEEK * 4;
84 Zeitgeist.TimeRange tr = new Zeitgeist.TimeRange (start, end);81 Zeitgeist.TimeRange tr = new Zeitgeist.TimeRange (start, end);
8582
86 var event = new Zeitgeist.Event ();83 var event = new Zeitgeist.Event ();
87 event.set_interpretation ("!" + Zeitgeist.ZG_LEAVE_EVENT);84 event.interpretation = "!" + Zeitgeist.ZG.LEAVE_EVENT;
88 var subject = new Zeitgeist.Subject ();85 var subject = new Zeitgeist.Subject ();
89 subject.set_interpretation (Zeitgeist.NFO_SOFTWARE);86 subject.interpretation = Zeitgeist.NFO.SOFTWARE;
90 subject.set_uri ("application://*");87 subject.uri = "application://*";
91 event.add_subject (subject);88 event.add_subject (subject);
9289
93 var ptr_arr = new PtrArray ();90 var array = new GenericArray<Zeitgeist.Event> ();
94 ptr_arr.add (event);91 array.add (event);
9592
96 Zeitgeist.ResultSet rs;93 Zeitgeist.ResultSet rs;
9794
98 try95 try
99 {96 {
100 rs = yield zg_log.find_events (tr, (owned) ptr_arr,97 rs = yield zg_log.find_events (tr, array,
101 Zeitgeist.StorageState.ANY,98 Zeitgeist.StorageState.ANY,
102 256,99 256,
103 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,100 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,
@@ -112,11 +109,11 @@
112 foreach (Zeitgeist.Event e in rs)109 foreach (Zeitgeist.Event e in rs)
113 {110 {
114 if (e.num_subjects () <= 0) continue;111 if (e.num_subjects () <= 0) continue;
115 Zeitgeist.Subject s = e.get_subject (0);112 Zeitgeist.Subject s = e.subjects[0];
116113
117 float power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>114 float power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>
118 float relevancy = 1.0f / Math.powf (index + 1, power);115 float relevancy = 1.0f / Math.powf (index + 1, power);
119 application_popularity[s.get_uri ()] = (int)(relevancy * MULTIPLIER);116 application_popularity[s.uri] = (int)(relevancy * MULTIPLIER);
120117
121 index++;118 index++;
122 }119 }
@@ -133,19 +130,19 @@
133 Idle.add (load_uri_relevancies.callback, Priority.LOW);130 Idle.add (load_uri_relevancies.callback, Priority.LOW);
134 yield;131 yield;
135132
136 int64 end = Zeitgeist.Timestamp.now ();133 int64 end = new DateTime.now_local ().to_unix () * 1000;
137 int64 start = end - Zeitgeist.Timestamp.WEEK * 4;134 int64 start = end - Zeitgeist.Timestamp.WEEK * 4;
138 Zeitgeist.TimeRange tr = new Zeitgeist.TimeRange (start, end);135 Zeitgeist.TimeRange tr = new Zeitgeist.TimeRange (start, end);
139136
140 var event = new Zeitgeist.Event ();137 var event = new Zeitgeist.Event ();
141 event.set_interpretation ("!" + Zeitgeist.ZG_LEAVE_EVENT);138 event.interpretation = "!" + Zeitgeist.ZG.LEAVE_EVENT;
142 var subject = new Zeitgeist.Subject ();139 var subject = new Zeitgeist.Subject ();
143 subject.set_interpretation ("!" + Zeitgeist.NFO_SOFTWARE);140 subject.interpretation = "!" + Zeitgeist.NFO.SOFTWARE;
144 subject.set_uri ("file://*");141 subject.uri = "file://*";
145 event.add_subject (subject);142 event.add_subject (subject);
146143
147 var ptr_arr = new PtrArray ();144 var array = new GenericArray<Zeitgeist.Event> ();
148 ptr_arr.add (event);145 array.add (event);
149146
150 Zeitgeist.ResultSet rs;147 Zeitgeist.ResultSet rs;
151 Gee.Map<string, int> popularity_map = new Gee.HashMap<string, int> ();148 Gee.Map<string, int> popularity_map = new Gee.HashMap<string, int> ();
@@ -155,7 +152,7 @@
155 uint size, index;152 uint size, index;
156 float power, relevancy;153 float power, relevancy;
157 /* Get popularity for file uris */154 /* Get popularity for file uris */
158 rs = yield zg_log.find_events (tr, (owned) ptr_arr,155 rs = yield zg_log.find_events (tr, array,
159 Zeitgeist.StorageState.ANY,156 Zeitgeist.StorageState.ANY,
160 256,157 256,
161 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,158 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,
@@ -169,22 +166,22 @@
169 foreach (Zeitgeist.Event e1 in rs)166 foreach (Zeitgeist.Event e1 in rs)
170 {167 {
171 if (e1.num_subjects () <= 0) continue;168 if (e1.num_subjects () <= 0) continue;
172 Zeitgeist.Subject s1 = e1.get_subject (0);169 Zeitgeist.Subject s1 = e1.subjects[0];
173170
174 power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>171 power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>
175 relevancy = 1.0f / Math.powf (index + 1, power);172 relevancy = 1.0f / Math.powf (index + 1, power);
176 popularity_map[s1.get_uri ()] = (int)(relevancy * MULTIPLIER);173 popularity_map[s1.uri] = (int)(relevancy * MULTIPLIER);
177174
178 index++;175 index++;
179 }176 }
180 177
181 /* Get popularity for web uris */178 /* Get popularity for web uris */
182 subject.set_interpretation (Zeitgeist.NFO_WEBSITE);179 subject.interpretation = Zeitgeist.NFO.WEBSITE;
183 subject.set_uri ("");180 subject.uri = "";
184 ptr_arr = new PtrArray ();181 array = new GenericArray<Zeitgeist.Event> ();
185 ptr_arr.add (event);182 array.add (event);
186183
187 rs = yield zg_log.find_events (tr, (owned) ptr_arr,184 rs = yield zg_log.find_events (tr, array,
188 Zeitgeist.StorageState.ANY,185 Zeitgeist.StorageState.ANY,
189 128,186 128,
190 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,187 Zeitgeist.ResultType.MOST_POPULAR_SUBJECTS,
@@ -198,11 +195,11 @@
198 foreach (Zeitgeist.Event e2 in rs)195 foreach (Zeitgeist.Event e2 in rs)
199 {196 {
200 if (e2.num_subjects () <= 0) continue;197 if (e2.num_subjects () <= 0) continue;
201 Zeitgeist.Subject s2 = e2.get_subject (0);198 Zeitgeist.Subject s2 = e2.subjects[0];
202199
203 power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>200 power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>
204 relevancy = 1.0f / Math.powf (index + 1, power);201 relevancy = 1.0f / Math.powf (index + 1, power);
205 popularity_map[s2.get_uri ()] = (int)(relevancy * MULTIPLIER);202 popularity_map[s2.uri] = (int)(relevancy * MULTIPLIER);
206203
207 index++;204 index++;
208 }205 }
@@ -290,18 +287,26 @@
290 var event = new Zeitgeist.Event ();287 var event = new Zeitgeist.Event ();
291 var subject = new Zeitgeist.Subject ();288 var subject = new Zeitgeist.Subject ();
292289
293 event.set_actor ("application://synapse.desktop");290 event.actor = "application://synapse.desktop";
294 event.set_interpretation (Zeitgeist.ZG_ACCESS_EVENT);291 event.interpretation = Zeitgeist.ZG.ACCESS_EVENT;
295 event.set_manifestation (Zeitgeist.ZG_USER_ACTIVITY);292 event.manifestation = Zeitgeist.ZG.USER_ACTIVITY;
296 event.add_subject (subject);293 event.add_subject (subject);
297294
298 subject.set_uri (app_uri);295 subject.uri = app_uri;
299 subject.set_interpretation (Zeitgeist.NFO_SOFTWARE);296 subject.interpretation = Zeitgeist.NFO.SOFTWARE;
300 subject.set_manifestation (Zeitgeist.NFO_SOFTWARE_ITEM);297 subject.manifestation = Zeitgeist.NFO.SOFTWARE_ITEM;
301 subject.set_mimetype ("application/x-desktop");298 subject.mimetype ="application/x-desktop";
302 subject.set_text (display_name);299 subject.text = display_name;
303300
304 zg_log.insert_events_no_reply (event, null);301 try
302 {
303 zg_log.insert_event_no_reply (event);
304 }
305 catch (Error err)
306 {
307 warning ("%s", err.message);
308 return;
309 }
305 }310 }
306 }311 }
307}312}

Subscribers

People subscribed via source and target branches