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

Proposed by Andrew Starr-Bochicchio
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 176
Merged at revision: 178
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
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nekhelesh Ramananthan Pending
Review via email: mp+183740@code.launchpad.net

This proposal supersedes a proposal from 2013-09-02.

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote : Posted in a previous version of this proposal

lgtm!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

FAILED: Autolanding.
No commit message was specified in the merge proposal. Hit 'Add commit message' on the merge proposal web page or follow the link below. You can approve the merge proposal yourself to rerun.
https://code.launchpad.net/~andrewsomething/ubuntu-clock-app/sunrise-sunset-fixes/+merge/183740/+edit-commit-message

review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

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

Subscribers

People subscribed via source and target branches