Merge lp:~andrewsomething/ubuntu-clock-app/sunrise-sunset-fixes into lp:ubuntu-clock-app/saucy

Proposed by Andrew Starr-Bochicchio
Status: Superseded
Proposed branch: lp:~andrewsomething/ubuntu-clock-app/sunrise-sunset-fixes
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 95 lines (+70/-1)
1 file modified
clock/EasterEgg.qml (+70/-1)
To merge this branch: bzr merge lp:~andrewsomething/ubuntu-clock-app/sunrise-sunset-fixes
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Approve
Review via email: mp+183546@code.launchpad.net

This proposal has been superseded by a proposal from 2013-09-03.

Commit message

Save sunrise/sunset times to local storage and only update once a day. Fixes: https://bugs.launchpad.net/ubuntu-clock-app/+bug/1200405

Description of the change

Save sunrise/sunset times to local storage and only update once a day. Fixes: https://bugs.launchpad.net/ubuntu-clock-app/+bug/1200405

To post a comment you must log in.
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

On a brief look, it is looking great. I will do one last detailed code review tomorrow before approving. Thanks for the merge proposal btw!

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Looks good. Just needs some small tweaks to help debugging in the future. I was thinking perhaps some debug output statements can be added so that a user can report the terminal output incase something is going wrong. For instance, in the saveSunTimes (date, sunRise, sunSet) function, can you add an output statement like,

Utils.log("Saving Sunrise/Sunset times to disk");

This way we can be sure that it was saved.

Also in the else case below, can you add an output statement "Retrieving sunrise/sunset times from disk".

88 + else if (status == XmlListModel.Ready) {
89 + sunriseTimeLabel.text = savedData[0][2];
90 + sunsetTimeLabel.text = savedData[0][3];
91 }

In line 22, can you replace "Default Ubuntu Touch Clock" with "Sunrise and Sunset Database"

22 + db = LocalStorage.openDatabaseSync("ubuntu-clock-app", "0.1", "Default Ubuntu touch clock", 1000);

In line 33, can you change that to "Error creating table in Sunrise/Sunset database".

33 + Utils.error("Error creating table in db: " + err);

review: Needs Fixing
175. By Andrew Starr-Bochicchio

Add more verbose debug output.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

A small nitpick, can you move,

63 + Utils.log("Saving Sunrise/Sunset times to disk");

into the try statement after tx.executesql step. This way it doesnt trigger until it is *actually* saved into disk.

review: Needs Fixing
176. By Andrew Starr-Bochicchio

Move debug statement after the sql is executed.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

lgtm!

review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clock/EasterEgg.qml'
2--- clock/EasterEgg.qml 2013-07-14 14:39:36 +0000
3+++ clock/EasterEgg.qml 2013-09-03 18:35:26 +0000
4@@ -20,11 +20,71 @@
5 import QtQuick 2.0
6 import Ubuntu.Components 0.1
7 import QtQuick.XmlListModel 2.0
8+import QtQuick.LocalStorage 2.0
9+
10+import "../common/ClockUtils.js" as Utils
11
12 // Qml Element to draw the easter egg (sunrise and sunset) on the analogue clock face.
13 Rectangle {
14 id: easterEggCircle;
15
16+ property var db: null
17+
18+ // Opens the local db if not already open. On the first call creates the table
19+ function openDB () {
20+ if(db !== null) return;
21+
22+ db = LocalStorage.openDatabaseSync("ubuntu-clock-app", "0.1", "Sunrise and Sunset Database", 1000);
23+
24+ try {
25+ db.transaction(function(tx){
26+ tx.executeSql('CREATE TABLE IF NOT EXISTS Easteregg(key INTEGER PRIMARY KEY, date TEXT, riseTime TEXT, setTime TEXT)');
27+ var table = tx.executeSql("SELECT * FROM Easteregg");
28+ if (table.rows.length == 0) {
29+ tx.executeSql('INSERT INTO Easteregg VALUES(?, ?, ?, ?)', [1, '', '', '']);
30+ };
31+ });
32+ } catch (err) {
33+ Utils.error("Error creating table in Sunrise/Sunset database: " + err);
34+ };
35+ }
36+
37+ //Read date last checked from DB
38+ function getSavedData () {
39+
40+ openDB();
41+
42+ var result = new Array();
43+ try {
44+ db.readTransaction(
45+ function(tx){
46+ var res = tx.executeSql('SELECT * FROM Easteregg WHERE key = 1');
47+ if (res.rows.length > 0) {
48+ result[0] = new Array();
49+ result[0][0] = res.rows.item(0).key;
50+ result[0][1] = res.rows.item(0).date;
51+ result[0][2] = res.rows.item(0).riseTime;
52+ result[0][3] = res.rows.item(0).setTime;
53+ };
54+ });
55+ } catch (err) {
56+ Utils.error("Error getting sunrise/sunset last checked date: " + err);
57+ }
58+ return result;
59+ }
60+
61+ function saveSunTimes (date, sunRise, sunSet) {
62+ openDB();
63+ Utils.log("Saving Sunrise/Sunset times to disk");
64+ try {
65+ db.transaction(function(tx){
66+ var res = tx.executeSql('UPDATE Easteregg SET date = ?, riseTime = ?, setTime = ? WHERE key = 1', [date, sunRise, sunSet]);
67+ });
68+ } catch (err) {
69+ Utils.error("Error saving sunrise/sunset times: " + err);
70+ };
71+ }
72+
73 // FIXME: Replace these constant values with user's location coordinates when automatic location detection is implemented.
74 property real latitude: 52.01;
75 property real longitude: 4.35;
76@@ -71,9 +131,18 @@
77 XmlRole { name: "sunsetTime"; query: "sunset/string()"; isKey: true }
78
79 onStatusChanged: {
80- if (status == XmlListModel.Ready) {
81+ var savedData = getSavedData();
82+ var checkedDate = savedData[0][1].split('T')[0]
83+ var date = new Date().toISOString();
84+ if (status == XmlListModel.Ready && checkedDate != date.split('T')[0]){
85 sunriseTimeLabel.text = getSunTime(sunRiseModel.get(0).sunriseTime);
86 sunsetTimeLabel.text = getSunTime(sunRiseModel.get(0).sunsetTime);
87+ saveSunTimes(date, sunriseTimeLabel.text, sunsetTimeLabel.text);
88+ }
89+ else if (status == XmlListModel.Ready) {
90+ Utils.log("Retrieving Sunrise/Sunset times from disk");
91+ sunriseTimeLabel.text = savedData[0][2];
92+ sunsetTimeLabel.text = savedData[0][3];
93 }
94 }
95 }

Subscribers

People subscribed via source and target branches