Monday, March 25, 2019

Evaluation of Careeach HR

The Careeach HR is a free tracker provided by Health Promotion Board. The following is a comparison with Garmin Forerunner 935. The comparison is one way. That is to say only compare what Careeach HR has to Forerunner similar functionality only. It is unfair to compare with all the available features of Forerunner 935.

1. Steps - Steps are fundamental feature however it is noted that Careeach HR always track about 10% less compared to Garmin even the steps setting are the same. Garmin seems to show slightly more steps than usual.

2. Heart Rate - Careeach heart rate measurements are very unstable. It can go above 150 while Forerunner shows a modest sub 90. The measurement can simply drops well below 80 while exercising and can drop out of continuous measure mode unexpectedly. Its auto mode is most unreliable. I always turn on continuous mode while exercising. Garmin shows a bit less accurate in auto mode but function well in continuous mode. I can use Garmin to control the heart beat rate but not Careeach. The latter heart beat goes up and down too much and too quickly. Careeach calculates max heart rate according to age. It will buzz user to slow down if the heart rate goes beyond heavy range. Garmin does not buzz user and its range is fixed percentage.

3. Display of the Careeach tracker is always off but can be activated by hand or a twist of the hand but often have to make very large angle swing of arm in order to activate it. Garmin does not have this feature as its display is always on. Both tracker will switch over to clock mode if it not in continuous measure mode. Garmin heart rate display will switch to clock mode after a while but it will stay if it is displayed in sports tracking mode.

4. Upload of data is a hassle. At times the HPB App has to be turned off and on a few times to make it update. Sometimes, the whole hand phone has to be rebooted to get it to work. Garmin update to HPB is via its apps. Although two steps are required but the updates are usually reliable.

5. Charging of Careeach is via USB but the display can some times go straight into full by just plugging in the tracker. The full charge display can stay till it run suddenly out of juice thus lost valuable data. Turning off and on the tracker does not help. Garmin charging can be a bit of problem due to contact issues but never have wrong display issue.

6. Careeach states that its tracker is splash proof. However, one tracker died after going though a light drizzle. Had to replace it. Garmin is water proof up to 50 meters.

7. Battery life of Careeach is way too low to be compared to Garmin. But it can last at least 10 hour of continuous heart beat tracking mode. It could last 2 days or more on normal mode.

8. Careeach will buzz user if they stay static for too long. I am not sure Garmin has it.

For a free device, Careeach HR could be used for tracking steps. Heart rate is at best good for indicator only. Just don't exercise in the rain or use quick charger to charge it.




Monday, March 18, 2019

Time and light

I am fascinated about time. There are already two blogs on the subject. This blog is to further elaborate on it against light.

The concept of time has already been discussed in earlier blogs. Light is the visible element that enables us to see things when light reflects on it. The speed of light is 299792458 meters per second or 1080,000,000 KPH. The speed of light according to WikiPedia is "a universal physical constant". However, X ray and laser seems to be travelling faster than light. Thus it is merely a reference value. Lets just take the reference value as the standard.

Now to see the light one second before now, you have to travel faster than the speed of light. It takes twice the speed to reach the light one second ago if you are travelling in the same direction as light. However, you can't travel in the opposite direction as light has not reflected from the object yet otherwise you would have gone past the object and chasing the light that does not exist. At best, you would have chased the past light in the other direction if the light is always on.

Travelling to see one second of the light before now needs you to travel at double the speed for one second. How long to take before you can catch up with the light one hour before at the same speed?

Now, even when you can see the light one second before, there is nothing you can do to alter it since it is already in the past. Therefore, the theory of changing the events that occur in the past is meaningless since you are only chasing the light not the object.

Even if you are chasing the object that travels away from you, you are merely reaching the object in its present state. There is no way you could have change anything before that state even if you travel ahead of it. You will only be able to see the "now" state of the object. Obviously you could change the environment before the object reach you but its not the future of the object, you are merely changing the "now" state of the environment so that the "now" state of the object and the "now" state of the environment where you are now coincides.

An analogy can be shown by a person shooting an arrow towards a target and another person moved the target before the arrow reaches it. It is just the "now" moment with the two object. 

Frankly speaking. The "now" state occurs on everything simultaneously. Nothing you do that could possibly change the "now" state as time is a measurement of a past event that is not changeable.

On the speed of light thing, a person can only withstand a certain G-force before he black out or dies. 1 G is 9.81 meters per sec. Light speed is 299792458 meters per sec. Without calculation, you will know that it is impossible to survive if you travel at the speed of light.

On the joking side. If there is no light then you can see nothing. How would you be able to chase the light at light speed? How is it possible to see anything?

One other thing, if you are travelling at the speed of light, those light you will see is probably a small area of light that is travelling in the parallel direction. How big a lens would be able to use to view an area of a square meter that is 299792458 meters away?



Friday, January 11, 2019

SQL Aggregate Function as Table using PHP

SQL aggregates as defined by netizens is "perform a calculation on a set of values to return a single scalar value". We often use aggregate functions with GROUP BY, HAVING clause of SELECT statements.

While it is very simple showing tables with just one aggregate or a set of aggregate functions using SELECT and GROUP BY then showing the table as retrieved by the SELECT statement, the table is practically vertical listing in nature. For example

SELECT states, people, SUM(revenue) FROM sales GROUP BY states,people order by states DESC

will show when you format it as table from the query result directly.

People   Revenue   State
Sam       100,000    Selangor
Ken        200,000    Selangor
Joe         100,000    Johor

What if you want to show all the people in the state regardless whether there are sales made by individual and the percentage of their Revenue for the state? It is quite impossible to do it in a single select statement.

The following method shows how to use a single statement to get a list of people and their revenue plus percentage of the group.

First we create an associative array from a list of people and populate it in the array.

$keys=array('Sam','Ken','Joe','April');
$values=array('Revenue'=>0,'Percent'=>0);
$total=0; //totals of the group
$revenue=array_fill_keys($keys,$values)

Retrieve the data using the previous SELECT statement like below. The example uses SQLite.

$db=new SQLite3('revenue.db');
$result=$db->query("select people, sum(revenue) from sales group by people");
while ($row=$result->fetchArray(SQLITE3_NUM))){
$ppl=$row[0];
$revenue[$ppl]['Revenue']=$row[1];
$total +=$row[1];
}
$db->close();
//do calculation and populate table
foreach ($revenue as $key=>$row){
$percent=round($row['Revenue']/$total*100,2);
echo " {$key}
{$row['Revenue']}{$percent}";}

Obviously, the above could be done by 2 queries. One to retrieve the overall total and the other one as above. However, what if you want to list the sales by date and show the people in columns? That is not an easy task representing it in one or two SQL.

You could retrieve the query by revenue grouped by date and people. Your array setting will be

$keys=array('Date','Sam','Ken','Joe','April');
$people=array_fill_keys($keys,$values)
$revenue=Array(); //you could fill the array with every date in the period you choose.

In the while loop, do as follows (assuming date is unix datetime),

$rdate=$row[0]; // the date field
if (!isset($revenue['A'.$rdate])){
$revenue['A'.$rdate] =$people;
$revenue['A'.$rdate]['Date']=date('m/d/Y',$$rdate);
) // set up the array and populate the 'Date' of the array for easy retrieval later
$people = $row[1] //the people field
$revenue['A'.$rdate][$people]=$row[2]; // the revenue field

With this you could populate the whole columns of people with date as first column. Displaying the table is then a breeze using the FOREACH example above.



Saturday, December 29, 2018

SQLite syncing with remote data to act as local data

There is a need to get a set of data from a remote server and distribute to a group of local computers. The data must not be deleted then inserted. The data also may not be available on remote server due to it being closed and removed.

If the data cannot be deleted (truncated) then the only way is to do "insert or ignore" so that existing data is either updated if it exists or inserted if it is not. Meanwhile, there is a problem of remote data does not exist while local data exists.

Well, it is quite easy. Two tables are used. One for the main table with a key index field and the other one only the key index field. Both table index uses the same field.

When importing data, both tables are inserted with the remote data. The second table was truncated before the import starts. This means the main table contains new and old data while the second table only contains the new data. At the end of importing, just simply delete from the main table where the index field not exists in second table. Thus only the imported data remains in the main table.

Example of the "insert or ignore" goes like this

Insert or ignore on maintable (f1, f2,f3....) values ('x1', 'x2, 'x3'...);update maintable set f2='x2', f3='x3' where f1='x1'

It seems that the above will insert and then update if the index is not found but it is still better than using two sql statements to insert or update plus one statement to check whether the index exists before doing either insert or update statement.

Example of the delete command goes like this

delete from maintable where  f1 not in (select f1 from secondtable)

The main table can then be access by local users.



Wednesday, December 26, 2018

Triggers in SQLite

Although triggers are common in databases. I seldom use it. Recently there is a need to pre-check before an insertion whether the number of records in a certain condition is within the quota set. Also, there is a need to check whether the specific field value exists already. Finally, there is a need to check whether one field content is in the list of another.

Under normal condition, I would set up three queries to check for it before doing the insertion of records. It will be untidy to code if this is done the normal way. Triggers then is the more cleaner way to do so.

The setting up is quite straight forward.

Create trigger before insert on for each row begin select

It then followed by the list of conditions

case when ((select....) > ) then raise(abort, "error message")
when ((select from where = NEW. ) is not null) then  raise(abort, "error message")
when ((select from where = NEW.) is not null) then raise(abort, "error message") end;
end;

In the script we just need a normal insert SQL with a exception check, (PHP try and catch) to get the error message. Just get the different message and act accordingly. It is very much cleaner in coding without much coding in the application.

This trigger can be inserted externally using normal SQL procedure. It can also be removed the same way. Obviously, same name trigger must be removed first before insert.

There are much more type of triggers. This one only talks about INSERT BEFORE.



Monday, December 10, 2018

Picasa Substitute

I used to take photos and add captions and tags to the photos using Google Picasa. Unfortunately it is no longer supported. I have a hard time finding substitute for it. Recently tried a new windows app called digiKam. It is quite suitable for use. The following are some similarities and dissimilarities.

1. Edit Geolocation.

Both can edit geolocation. Both are able to update multiple files at one time. digiKam have additional functionality to do GPS correlator (loading a GPX file and interpolate the geolocation into the picture). Currently uses GeoSetter to do it.

2. Edit Caption/IPTC/XMP

Used the menu item of digiKam to edit IPTC. Although it can edit individual but it is a hassle if multiple files of the same group need to be edited.  Later, it was discovered that the right hand column has "Captions" can do multiple file update. Picasa has an advantage in that you could type in the keywords and it will auto suggest. digiKam provide a list of tags for you to select. Each has its own merits.

3. Search for tags.

DigiKam provide a tag listing where you can instantly apply a filter by choosing the tags. Picasa does it by typing into a search field. The latter can just type partially and the list will automatically match the partial words. I would say the latter is more flexible.

4. Grouping.

Picasa has a "starred" feature that allows a selection of pictures to be listed by choosing a set. digiKam does not have it but since I have been using tags to provide a list like "special", "flowers" etc. It is a matter of adding the "starred" tag and use it for listing under tags. However, it is slightly inconvenient as I have to fish the tag out from thousands of tags. Maybe I should use the star setting provided by digiKam instead.

5. External change of the tags.

DigiKam seems to be unable to respond to newly changed tags outside of its app (unless it is restarted). Picasa does not have this problem.

6. Maps

Picasa has maps but since the support is no longer available, it has not been working. Any individual change to the geolocation has to use GeoSetter. GeoSetter is kind of slow as it does a lot of background work. digiKam can show the icon/bubble on OpenStreetMap and can add the geolocation by dragging the file into the map.

7. Album listing.

Picasa can scroll through the albums. digiKam can only show within the same album. It is a disadvantage as I sometimes have to scroll through a list of albums to identify the observations.

8. Maps grouping - In the catalog setting there is another maps facility. This one allows to select by geolocation. A map is displayed on all pictures that have geolocation. You can select an area and it will display all pictures in the location. Very convenient tool to identify species in the same region.

In conclusion, no two app works exactly the same. Some will have advantages and disadvantages over others. digiKam is one app that is quite close to what I need to manage plants and animals photos with location info and tags by Gendre and Family for easy reference and research.




Thursday, November 01, 2018

Setting up Google Play on Mi5X

I always have problem with Google Play using Mi5X. It is not available when shipped. Installed Google Play Apk from websites and it can launch Google Play.

One of it works just fine but the other one will prompt "Server Busy" on and off. Following netizen advice to totally remove Google Services and Google Play store. The result is that I cannot restore Google Play at all despite installing Google Services and Google Play apk from sites that provide the apk. Even my account information does not list the Mi5X as a device.

While looking for ways to restore back Google Play by searching for "Google" in Mi Store, I notice Mi Store has a prompt saying something like it is not able to list Google products due to limitation. Thus whatever advice on the web does not apply.

Searching for "MiUi Google Play" turn out something like a installer for Google Play. Tried to go to Mi Store again and look for "谷歌安装器”。 It still turn out nothing.

This calls for drastic measures. I notice there is a "去豌豆荚搜索“ in Mi Store when searching for "Google". Tried that and it  actually shows one app called "谷歌安装器”. It is not by Google but look rather like a "Google Play Installer".

Followed instruction to allow for "unknown sources" in Settings.Additional Settings,Privacy. The apk was installed successfully. Running it and it prompts for installation of a number of Google Apps. Upon completion, Google Play can start without issue.

The next thing to do is just wait and see if "server busy" prompt will show again.