Lazarus

Miscellaneous => Other => Topic started by: Handoko on August 11, 2020, 07:52:25 pm

Title: CATWW
Post by: Handoko on August 11, 2020, 07:52:25 pm
Clocks Around The World-Wiser
-----------------------------

A world-clock for the community made by the community
Version 0.1 Now version 0.2


From the previous discussions, we got an idea to build a world clock.
Here is the demo, all suggestions are welcome.

Todo list (Handoko's tasks):
Requirement:

To able to compile it, BGRABitmap need to be installed. Here is how to install BGRABitmap:
Lazarus main menu > Package > Online Package Manager > BGRABitmap > Install > From repository
Title: Re: CATWW
Post by: JLWest on August 11, 2020, 11:00:23 pm
I like it.
I kind of like the square clock. The header has some possibilities.

Title: Re: CATWW
Post by: MaxCuriosus on August 12, 2020, 12:52:31 am
My suggestions:

1. Round clock only.
2. Short and thick tail ("counter-weight") to each hand
3. Add a digital elapsed time that starts when the program starts.
Title: Re: CATWW
Post by: lainz on August 12, 2020, 03:06:54 am
Indeed it runs slow, all the clocks are not sinced I say when they move the hands.

And it behaves strange on Windows, I cant move the window not close it, I must kill the app.
Title: Re: CATWW
Post by: Handoko on August 12, 2020, 04:36:09 am
3. Add a digital elapsed time that starts when the program starts.

Thank you for your suggestions, but I do not fully understand. Can you explain more about it?
Title: Re: CATWW
Post by: eny on August 12, 2020, 12:36:05 pm
On Windows the main form, that is hidden, is still the 'focused' one.
So the clock form cannot be changed (mininimized/maximized etc.).
Title: Re: CATWW
Post by: Handoko on August 12, 2020, 12:55:12 pm
Thank you for informing this issue. I use Linux, I have no such problem.

I'm not sure but I found I accidentally disabled the Clock form., maybe this is the culprit that cause the problem. I'll inspect it later.
Title: Re: CATWW
Post by: MaxCuriosus on August 12, 2020, 01:00:17 pm
3. Add a digital elapsed time that starts when the program starts.

Thank you for your suggestions, but I do not fully understand. Can you explain more about it?

Handoko,
visualize  your clock with a transparent background and a separated but "docked" rectangle below that displays the elapsed time in digital form.
Title: Re: CATWW
Post by: Handoko on August 12, 2020, 01:21:58 pm
What would the elapsed time used for?
My phone has elapsed timer, I used it as an alarm when I am boiling water.
Title: Re: CATWW
Post by: eny on August 12, 2020, 01:52:59 pm
Did a quick test on windows with laz x64 with a 4x4 grid.
Watching time passing like thas has a medidative effect  :D

Title: Re: CATWW
Post by: Handoko on August 12, 2020, 02:13:56 pm
Thank you for the suggestions.

I thought about using class. But I choose the old-school way (not using class) so more newbies can study the code easier.

Previously I used panels. But I decided not to use it because think drawing it directly on a single canvas will have better performance.

I am doing the optimization now, I managed to make it run a bit faster. Yes, I saw some flicker issue and already used buffer.
Title: Re: CATWW
Post by: TRon on August 12, 2020, 04:34:12 pm
@Handoko:

Nice looking !

You already am aware of the underpowered hw I test on, but wanted to let you know as an indication that in case I activate all clocks and making the form about a quarter size of my screen (1920x1080) that it takes about 4-5 seconds for the seconds-hands to 'update'.
Title: Re: CATWW
Post by: MathMan on August 12, 2020, 04:49:12 pm
Thank you for the suggestions.

I thought about using class. But I choose the old-school way (not using class) so more newbies can learn from it.

Previously I used panels. But I decided not to use it because think drawing it directly on a single canvas will have better performance.

I am doing the optimization now, I managed to make it run a bit faster. Yes, I saw some flicker issue and already used buffer.

First I have to admit I do not know anything about BGRABitMaps. But looking through 'Clocks.pas' I do see that you are doing three affine transformations (rotation plus elongation I assume) every timer tick. Affine transforms are expensive operations usually. So this can be improved massively, if you are willing to spend more memory. Just pre calculate the 60 affine transforms required for every hand (seconds, minutes & hours) and then simply map them on the clock background at the timer tick. You would of course need to re-calculate these in case of a canvas re-size then.

Cheers,
MathMan
Title: Re: CATWW
Post by: lainz on August 12, 2020, 05:26:55 pm
You don't need to calculate the 60 transformations if you want to cache them. For example you can calculate a quarter, say the first 15, then flip horizontally and vertically as needed, that's much faster.
Title: Re: CATWW
Post by: MathMan on August 12, 2020, 05:36:53 pm
You don't need to calculate the 60 transformations if you want to cache them. For example you can calculate a quarter, say the first 15, then flip horizontally and vertically as needed, that's much faster.

Yeah, good point. Would make the update on the timer tick a bit more complex, but would reduce the memory footprint by 4. Sounds like a good compromise.
Title: Re: CATWW
Post by: Handoko on August 12, 2020, 05:41:14 pm
Thank you MathMan for the suggestion.

Yes, you're right. I already figured it out and done it before reading your post. It really improves the performance.

Not only caching it the images, it now also generates multi resolution images to improve the performance when user resizing the form. On my benchmark, the more it scales, the longer the time it needed. So I made it auto generates several resolutions when loading images or user switches skin.

@TRon

Yes, version 0.1 was quickly built. Now I'm adding multi-res image generation, image caching, using buffer instead of direct drawing. Hope the version 0.2 will have good performance.
Title: Re: CATWW
Post by: Handoko on August 18, 2020, 12:39:51 pm
CATWW Version 0.2

The performance has been improved. And now user can choose which city to be showed on the clock by clicking on the clock. Because of the size of source code (+images) is now too large to be added on this post, I put the downloadable source code on the first post https://forum.lazarus.freepascal.org/index.php/topic,50989.0.html (https://forum.lazarus.freepascal.org/index.php/topic,50989.0.html)

To keep it simple, the whole source code is only separated in 3 parts:

How to add the time shift calculation into the code?


The time zone lookup and time calculation code should be put in the DataSync.pas.

I quickly generated the time zone data and saved it in Cities.txt. I use TStringList's LoadFromFile and name-value pair features. It is a quick solution. But if you think it should use a database, just do it and change the related code.

Here is the interface part of DataSync.pas:
Code: Pascal  [Select][+][-]
  1. unit DataSync;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls, Grids, DateUtils;
  9.  
  10. const
  11.   MaxRows    = 2;
  12.   MaxColumns = 3;
  13.   MaxClocks  = MaxRows*MaxColumns;
  14.  
  15. var
  16.   CityList: TStringList = nil;
  17.   Cities:   array[1..MaxClocks] of string = // Empty string means
  18.               ('', '', '', '', '', '');     // to use system time
  19.  
  20. procedure LoadCities;                // Should be called when program start
  21. procedure FreeAllData;               // Should be called when program exit
  22. function  GetSystemTimeName: string; // How to name the system time
  23. function  GetCityName(Index: integer): string;     // Index start from 1
  24. function  GetCityTimeZone(Index: Integer): string; // Index start from 1
  25. procedure GetCityTime(Index: Integer; ThisSystem: TTime; var Hour, Minute: Word);
  26. function  SelectCity: string;        // Show a popup for selecting a city
  27.  
  28. implementation
  29.  
  30. type
  31.  
  32.   { TCityPopup }
  33.  
  34.   TCityPopup = class(TForm)

CityList is used to store the data loaded from Cities.txt. And Cities is the data that stores the user selected city for each of the clock. The code for loading the data should be put in LoadCities and FreeAllData is for freeing all the in-memory objects.

GetSystemTimeName is the name for the clock that using the computer time. Change the return string to whatever you think better.

I do not have solution for the time zone calculation, I quickly created a fake time calculation, which is not correct. It is in GetCityTime. GetCityName is used for converting the loaded data for the city name and GetCityTimeZone are the data for saved time zone. The code of GetCityTime, GetCityName and GetCityTimeZone need to be changed.

SelectCity will be called if user want to change the city for the clock (which can be done by clicking the clock). It will runtimely create a popup based on TCityPopup class. I tested the TCityPopup on a separated code, the performance was still okay even the item count has reached 300.000. It uses TStringGrid for the drawing but data is maintained separately.

Performance improvement


The code now uses cache system and multi-resolution images, which generated at runtime. It run pretty good on my test, although I wish resizing the clocks can be faster.

Please test it.
Do it run correctly on different environment?
And do you think the performance is acceptable?

Any suggestions and criticisms are welcome.

The source code can be downloaded here:
https://forum.lazarus.freepascal.org/index.php/topic,50989.0.html (https://forum.lazarus.freepascal.org/index.php/topic,50989.0.html)
Title: Re: CATWW
Post by: Lulu on August 18, 2020, 03:56:07 pm
tested on Win10 64b and work very well  :)
Title: Re: CATWW
Post by: Handoko on August 18, 2020, 04:00:10 pm
Thank you.

Do you have any suggestions?
Title: Re: CATWW
Post by: Lulu on August 18, 2020, 04:14:58 pm
May be use opengl ? It will be faster and also improves the memory footprint of your application:
load the 4 images 1200x1200 as texture in the gpu memory and use matrix to resize/rotate each part of the clocks.
I think this could be done 'easily' with TBGLVirtualScreen, but I never realy use it.
Or use TOpenGLControl directly.
Regards
Title: Re: CATWW
Post by: JLWest on August 18, 2020, 05:46:44 pm
Works pretty well. Windows 10.

I like it.
Title: Re: CATWW
Post by: TRon on August 20, 2020, 08:49:29 pm
Thank you Handoko.

That is an impressive performance boost  :)

The tiny pi3b+ is now even able to show the maximum amount of clocks full-screen. In case it is then there is a small (almost unnoticeable) hick-up when two or more clock-hands needs to shift graphically but that is to be expected. Before, when the improvements were not in place, it was virtually impossible to get the window bigger then a quarter screen (and for comparison that quarter size window caused a 5 sec delay for the hands to shift). Other then that I can report that it takes a small amount of time to redraw the clocks on a resize of the window but, that is also expected and negligible.

No other flickering/stuttering etc. anymore.
Title: Re: CATWW
Post by: Handoko on August 21, 2020, 04:47:06 pm
Glad to know it is able to show full screen on Raspberry Pi 3b+.

So do you think the performance is okay and we don't need to use OpenGL or other graphics engine?

The version 0.1 is only a prototype without any performance optimization. I'm sure you ever heard "Premature optimization is the root of all evil". That's why it was very slow.

On version 0.2, I can see some short delay time when resizing. That is understandable because resizing will 'force' all caches to renew. I have some ideas that might make it better. I will try it on next version.

I'm already started working on version 0.3. The things are going to be added are mostly cosmetic improvements. Also fixing a memory leak issue, I was so careless that forget to free the multires images.

You don't need to calculate the 60 transformations if you want to cache them. For example you can calculate a quarter, say the first 15, then flip horizontally and vertically as needed, that's much faster.

I choose to calculate half of the images. Because some of the hands I planned are not symmetric.
Title: Re: CATWW
Post by: TRon on August 21, 2020, 11:10:25 pm
So do you think the performance is okay and we don't need to use OpenGL or other graphics engine?
Nah, I think it is more than ok-ish.

You can't expect miracles on such hardware, and besides that there comes a point where you have to draw a line (phun intended)  :D .

Quote
I'm sure you ever heard "Premature optimization is the root of all evil". That's why it was very slow.
I understand. It was by no means meant as criticism rather an observation that could serve as some sort of indication. I also wouldn't expect the new version to run on ... let's say ... a vic-20  :P

Quote
On version 0.2, I can see some short delay time when resizing. That is understandable because resizing will 'force' all caches to renew. I have some ideas that might make it better. I will try it on next version.
In case it kind of bothers you, then please feel free. Personally I find it more than acceptable.

Quote
I'm already started working on version 0.3.
Cool !

fwiw any improvement with regards to speed would be noticed on this little machine. And fixes are always welcome. Sorry as I haven't been able to provide feedback on such matters.
Title: Re: CATWW
Post by: bytebites on August 23, 2020, 08:19:11 am
See what happens if you select same timezone than your local time.
Title: Re: CATWW
Post by: TRon on August 23, 2020, 06:42:42 pm
See what happens if you select same timezone than your local time.
Could you elaborate on what I should be seeing (that you seem to suggest as wrong) ?
Title: Re: CATWW
Post by: winni on August 23, 2020, 08:02:59 pm
Hi!

Berlin Shows: 21:02
Germany is now: 20:02

Winni
Title: Re: CATWW
Post by: JLWest on August 23, 2020, 08:36:45 pm
@Winni

I think that's because he is using test data he made up and not a dataset that has offsets with DST.
Title: Re: CATWW
Post by: TRon on August 23, 2020, 08:51:50 pm
Berlin Shows: 21:02
Germany is now: 20:02
Yes, I know  :)

I quote user Handoko
Quote
I quickly generated the time zone data and saved it in Cities.txt. I use TStringList's LoadFromFile and name-value pair features. It is a quick solution. But if you think it should use a database, just do it and change the related code.
So, that could not have been what user bytesbytes meant ?

If the wrong DST/UTC offset is bothering someone then you can simply fix that by editing cities.txt and correct the values manually

I am working on a more robust/satisfactory solution, which is already working for me but I need to fix some loose ends (and am actually quite busy doing other things atm).
Title: Re: CATWW
Post by: winni on August 23, 2020, 09:17:35 pm
Hi!

Tron wants to change now the timezone of Berlin. And at the end of October  change it back???

The secrect is called daylight saving. That is the error because it is not taken in account.
There is a up-to-date table needed with the used timezones and if there is daylight saving.
And the algorithm for starting and ending.
A lot of countries do their own stuff (Chile, Israel, USA,...)

The law (!!)  for EU is:
ds start: last Sunday in March, 1:00 UTC
ds end: last Sunday in October, 1:00 UTC

[That it not ending in September anymore is a gift of Maggie Thatcher.
This is the only positive one can say about her]

And there are always changes in the daylight saving:
Russia and Turkey abolished it in the last years.
USA stopped the confusion: All Coutries start and end at the same day.
Except Arizona (Hello JLWest)

And in Canada Quebec has ds but only west of -63° longitude ....

Winni
Title: Re: CATWW
Post by: TRon on August 23, 2020, 09:37:06 pm
Tron wants to change now the timezone of Berlin. And at the end of October  change it back???
Yes, exactly !

As said: it is already working for me  :D

Quote
And there are always changes in the daylight saving:
I should have that covered as well.

Quote
Russia and Turkey abolished it in the last years.
Their loss ... or gain... not sure :D

I thank you for your extended reply winni but tbh I am/was already aware of all these things.

Please have a little faith and patience.

User Handoko was/is prioritising on graphics and related speed issues. The rest will (eventually) be added.
Title: Re: CATWW
Post by: winni on August 23, 2020, 09:52:06 pm
Hi!

Okay. Did not want to disturb work in progress ...

But lets look at the speed:

BGRABitmap is fast.
I don't know nothing about its speed on the Raspi toys  but a normal PC should draw 6 whole clocks in < 100 ms.

So is the cashing realy needed for the toys?
On a PC it is useless and consumes a lot of RAM.

Winni
Title: Re: CATWW
Post by: TRon on August 23, 2020, 10:30:44 pm
Okay. Did not want to disturb work in progress ...
No problem. I thank you for your expressing your concerns.

Quote
I don't know nothing about its speed on the Raspi toys  but a normal PC should draw 6 whole clocks in < 100 ms.
On a tiny pi3b (no +), no hardware accelerated drivers in place, it takes 5-7 seconds (3b closer to 7, 3b+ closer to 5) to update all clocks when drawing it into a window about a quarter of the size of a 1920x1080 screen resolution.

Quote
So is the cashing realy needed for the toys?
If you noticed the prepare progress bar every time you make a change with regards to the placement of the clocks, that time-lapse you see there is needed for every update. I am aware that the caching includes drawing half of all the positions so that time can be roughly divided by 30 to get an actual indication on how long it actually takes to draw the hands (each second). Then you would have to multiply that time-duration by 6 (for 6 clocks).

That takes a whole lot of time on such hardware like a Pi.

With the latest changes made by Handoko it is now possible to actually update each clock every second, with a minor hick-up if 2 or more hands need to be drawn/updated as well. Note, it is only a hick-up that you'll be able to notice in case you are focusing on 6 clocks that occupy the whole screen (1920x1080, full size window) as humans tend to notice when a timely pattern is disturbed (for only the tiniest of moments). It isn't even noticeable on a smaller sized window, although there again humans tend to focus on the pattern (of the seconds hand) and might be able to observe even the tiniest of a delay that so that the time-frame between two (graphical) updates isn't exactly 100% the same as the previous one.

Perhaps Handoko or someone else is able to explain this better.

PS: It is not my motive to have catww actually run presentable on a pi, but the lowest of specs can usually act as a good indicator. Whether or not you wish to actually act on such indicators is an entirely other discussion  :)

Quote
On a PC it is useless and consumes a lot of RAM.
There are a couple of implications whit saying that
1. it is always a fine line between speed and caching
2. What exactly is a PC ? Should your old pentium/core duo still running XP (or even older) also count as a PC ? Should catww be able to run there acceptable too ?
3. What is a lot of ram ? These days, a standard machine runs with 8 cores and should at least have 32gb of ram. How much ram does the caching actually take ? Even the pi (1 GB memory !) is able to handle that ...

My reply is not meant to criticise, rather to hopefully make you understand that there are pastures everywhere. Some are green, others yellow or even pink. Picking the right color is a major headache. Put them all into a bowl and stir it and you have a great chance of ending up with a terrible colour  :D
Title: Re: CATWW
Post by: winni on August 23, 2020, 10:49:19 pm
Hi!

@ Tron

Thanx for the explanations.

Question: Did Circular meanwhile implement the XOR feature for drawing?

This could help a lot to speed up the drawings of the clocks.

Old tricks with Delphi Canvas:
Draw a line ( a hand).
On the next second:
Set drawMode to XOR. Draw the line again: it is deleted.
And now draw the new line.

I don't  now nothing about Raspi and other toys.
But from my history I know a lot of slow computers .....

Winni
Title: Re: CATWW
Post by: JLWest on August 24, 2020, 02:26:37 am
Actually we have the easiest DST calculation in the US. We don't have a DST. We are MST 24/7/365 and we like it that way.
Title: Re: CATWW
Post by: Handoko on August 24, 2020, 05:46:07 am
See what happens if you select same timezone than your local time.

In my previous posts, I already mentioned:
- I quickly generated the time zone data (which I wasn't sure they were correct)
- I do not have solution for time zone calculation (because I didn't follow the previous discussions)
- v0.2 used a fake time calculation

And honestly, it was my first time to learn what daylight saving is from my pm with winni. The v0.2 did not take daylight saving into account.

 :-[ But the most serious problem is, if you look into the DataSync.pas there is no code to get the computer's time zone. That means it will treat the user time zone as GMT +0.00.

It's just version 0.2, many things haven't implemented yet. And as far as I know, TRon is now working on the database and synchronization. It should be working correctly on version 1.0.

Draw a line ( a hand).

No, I do not want to use line drawing. I knew it fast but it doesn't look good. You will understand why if you see the version 0.3, which I'm still working on.

The first things came into my head when I hear a community clock project:
It is a community project, it should not look amateurish. Lazarus/FPC has cross compile ability, the program should be able to run on different OSes, hardware and even old machines. I like KISS concept and I want others to be able to study the code easily. That's why I put many comments inside the code and it is written using traditional procedural style. I know many novice programmers can understand procedural approach easier than OOP style. If it were my own project, I would write it in full OOP approach.

On a PC it is useless and consumes a lot of RAM.

I already mentioned on previous post, in case you miss it. It had a memory leak issue on v0.2. It has been fixed on v0.3. Memory usage is highly depended on the form size. My my test on 1920x1080 full screen, the memory usage CATWW v0.3 never reaches 140 MB.




Why it is slow and need much memory?

Hey, now is 2020 do you think we should program a clock that looks like the one 3 decades ago?

Line drawing is fast but they looks jaggy. Antialiased lines are better, with a bit sacrifice of performance. But instead of using drawing functions, I use image scaling and rotating. Unfortunately scaling and rotating is expensive especially on non-hardware-accelerated engine.

The clock painted is using 4 layers of images:
- The background
- The hour hand
- The minute hand
- The second hand
Also if user choose to show 6 clocks, that will be repeated six times.

To make it faster, I use cache. It greatly improves the performance. But a problem happens when resizing the clock. If user resize the clock (by resizing the form), all the caches will need to be refreshed. That why it has performance drop when resizing.

So, I implemented a new trick: runtime-generated multi-resolution image. When refreshing the cache, it chooses the nearest larger images. The more resolutions prepared the more performance improved when resizing.

I did some research, nowadays many users use 1920x1080 resolution or more. On my test, 1200x1200 is the best for the clock images even running it on a large screen. Keeping such huge images in memory consumes a lot of memory. If I choose to prepare 20 different resolutions, it will greatly improve the performance. But for memory friendly, CATWW v0.2 only uses 5 different resolutions: 1200, 1000, 800, 600, 400.

Do you know how much images need to be generated for simply 5 different resolutions? Not 5, but 5 x 4 = 20 images.

The caching system and multi-resolution image concept explain why it requires a lot memory. But memory is cheap, I think it's okay.
Title: Re: CATWW
Post by: JLWest on August 24, 2020, 06:13:05 am
It works great on my machine.

And it works great on my $275 laptop, both  run Windows 10 Pro:

A Samsung Chromebook 4 Chrome OS 11.6" HD Intel Celeron Processor N4000 4GB RAM 32GB eMMC Gigabit Wi-Fi - XE310XBA-K01US $275
 
Title: Re: CATWW
Post by: TRon on August 24, 2020, 06:29:01 am
Thanx for the explanations.
You are very welcome.

A bonus treat for you (working test output):
Code: [Select]
Creating timer
Entering sleepmode
Every 5 secs a timer event will write the current clock's information to the console
0 ->  local computer time | 25 October 2020 02:59:51 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:59:51 (CEST)
2 ->      Atlantic/Faeroe | 25 October 2020 01:59:51 (WEST)
3 ->       America/Bogota | 24 October 2020 19:59:51 (-05)
4 ->           US/Arizona | 24 October 2020 17:59:51 (MST)
5 ->          Asia/Taipei | 25 October 2020 08:59:51 (CST)

0 ->  local computer time | 25 October 2020 02:59:56 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:59:56 (CEST)
2 ->      Atlantic/Faeroe | 25 October 2020 01:59:56 (WEST)
3 ->       America/Bogota | 24 October 2020 19:59:56 (-05)
4 ->           US/Arizona | 24 October 2020 17:59:56 (MST)
5 ->          Asia/Taipei | 25 October 2020 08:59:56 (CST)

0 ->  local computer time | 25 October 2020 03:00:01 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:00:01 (CET)
2 ->      Atlantic/Faeroe | 25 October 2020 01:00:01 (WET)
3 ->       America/Bogota | 24 October 2020 20:00:01 (-05)
4 ->           US/Arizona | 24 October 2020 18:00:01 (MST)
5 ->          Asia/Taipei | 25 October 2020 09:00:01 (CST)

0 ->  local computer time | 25 October 2020 03:00:06 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:00:06 (CET)
2 ->      Atlantic/Faeroe | 25 October 2020 01:00:06 (WET)
3 ->       America/Bogota | 24 October 2020 20:00:06 (-05)
4 ->           US/Arizona | 24 October 2020 18:00:06 (MST)
5 ->          Asia/Taipei | 25 October 2020 09:00:06 (CST)
Does that sound about right for your timezone and the listed date/time ?

Quote
Question: Did Circular meanwhile implement the XOR feature for drawing?
I have no idea tbh. I am not very familiar with BGRABitmap/Tools/Utils  :-[

Quote
Old tricks with Delphi Canvas:
Draw a line ( a hand).
On the next second:
Set drawMode to XOR. Draw the line again: it is deleted.
And now draw the new line.
I am aware of the tricks that can be used on under-powered/old machines. Although for most of them they 'invented' assembler or nice custom chips such as a blitter, but the basic principles are still the same.

Quote
I don't  now nothing about Raspi and other toys.
But from my history I know a lot of slow computers .....
With regards to the latter, I am as well and with regards to the former... I just happen to have some around.... actually used for quite other purposes but this will do as well :)
Title: Re: CATWW
Post by: Handoko on August 24, 2020, 02:20:16 pm
Code: [Select]
Creating timer
Entering sleepmode
Every 5 secs a timer event will write the current clock's information to the console
0 ->  local computer time | 25 October 2020 02:59:51 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:59:51 (CEST)
2 ->      Atlantic/Faeroe | 25 October 2020 01:59:51 (WEST)
3 ->       America/Bogota | 24 October 2020 19:59:51 (-05)
4 ->           US/Arizona | 24 October 2020 17:59:51 (MST)
5 ->          Asia/Taipei | 25 October 2020 08:59:51 (CST)

0 ->  local computer time | 25 October 2020 02:59:56 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:59:56 (CEST)
2 ->      Atlantic/Faeroe | 25 October 2020 01:59:56 (WEST)
3 ->       America/Bogota | 24 October 2020 19:59:56 (-05)
4 ->           US/Arizona | 24 October 2020 17:59:56 (MST)
5 ->          Asia/Taipei | 25 October 2020 08:59:56 (CST)

0 ->  local computer time | 25 October 2020 03:00:01 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:00:01 (CET)
2 ->      Atlantic/Faeroe | 25 October 2020 01:00:01 (WET)
3 ->       America/Bogota | 24 October 2020 20:00:01 (-05)
4 ->           US/Arizona | 24 October 2020 18:00:01 (MST)
5 ->          Asia/Taipei | 25 October 2020 09:00:01 (CST)

0 ->  local computer time | 25 October 2020 03:00:06 (lct)
1 ->        Europe/Berlin | 25 October 2020 02:00:06 (CET)
2 ->      Atlantic/Faeroe | 25 October 2020 01:00:06 (WET)
3 ->       America/Bogota | 24 October 2020 20:00:06 (-05)
4 ->           US/Arizona | 24 October 2020 18:00:06 (MST)
5 ->          Asia/Taipei | 25 October 2020 09:00:06 (CST)
Does that sound about right for your timezone and the listed date/time ?

Good to know you already have the code for time calculation/synchronization. But because the version 0.3 is all about cosmetic improvements, I will integrate it into CATWW on version 0.4 or higher.

It works great on my machine.

And it works great on my $275 laptop, both  run Windows 10 Pro:

A Samsung Chromebook 4 Chrome OS 11.6" HD Intel Celeron Processor N4000 4GB RAM 32GB eMMC Gigabit Wi-Fi - XE310XBA-K01US $275

Thank you for informing that it also runs good on Intel Celeron hardware.
Title: Re: CATWW
Post by: Handoko on August 24, 2020, 03:15:51 pm
The version 0.3 is in the middle of finish, it is the time to discuss the non-programming things.

Name and Logo


CATWW - Clock Around the World-Wiser is the name. Is it okay? Or maybe any of you have a better suggestion?

The name CATWW makes me think a cat and 2x letter w. So I drew a logo, see the attachment below. Any better idea for the logo?

License

Can anyone tell me as the original authors of the program (me, JLWest, TRon), can we dual-license it in proprietary and GPL? Is there any GPL's rule that prohibit the original author of the software to dual-license or re-license it to closed software.

The CATWW published on this forum is in GPL, anyone can study, modify and improved it as long as they follow the GPL's rules. I may keep maintaining and improving it and it will be stay in GPL.

But who knows, maybe some time in the future me, JLWest and TRon will team up to start a software development company and we may improve the CATWW, re-license it as commercial product and make money from it.  ;)

I checked the license of the tools/libraries are used by CATWW:
Those above are used to build CATWW, it seems none of them prohibits us to release it as closed/commercial software.

Also, I want to use this opportunity to declare:
Quote
Me - Handoko as the graphics programmer of CATTW, give permission to JLWest and TRon to use the code and any resources I contributed for CATTW, and to modify and improve, and to re-license it to whatever they like in the future including proprietary and commercial licenses.

Database and Online Service

CATWW need data for time zone. Does anyone know where can we download the database and use it freely including for closed/commercial projects.

CATWW will have to ability to synchronize the data with online services. Does anyone know any of such service that provide it free? It will be better if it can be used on closed/commercial projects.
Title: Re: CATWW
Post by: TRon on August 24, 2020, 08:54:56 pm
Good to know you already have the code for time calculation/synchronization. But because the version 0.3 is all about cosmetic improvements, I will integrate it into CATWW on version 0.4 or higher.
No problem Handoko, as I was kind of expecting that would be the case.

As for a fun fact: the moment planet earth consists of 3 days (look for the last 3 entries).
Code: [Select]
0 ->  local computer time | 24 August 2020 12:00:07 (lct)
 1 ->        Europe/Berlin | 24 August 2020 12:00:07 (CEST)
 2 ->      Atlantic/Faeroe | 24 August 2020 11:00:07 (WEST)
 3 ->       America/Bogota | 24 August 2020 05:00:07 (-05)
 4 ->           US/Arizona | 24 August 2020 03:00:07 (MST)
 5 ->          Asia/Taipei | 24 August 2020 18:00:07 (CST)
 6 ->           Asia/Kabul | 24 August 2020 14:30:07 (+0430)
 7 ->        Asia/Katmandu | 24 August 2020 15:45:07 (+0545)
 8 ->        Europe/London | 24 August 2020 11:00:07 (BST)
 9 ->         Pacific/Niue | 23 August 2020 23:00:07 (-11)
10 ->       Pacific/Tarawa | 24 August 2020 22:00:07 (+12)
11 ->   Pacific/Kiritimati | 25 August 2020 00:00:07 (+14)
Being able to work/experiment with virtual dates and times actually turns out to be quite fun !  :)
Title: Re: CATWW
Post by: TRon on August 24, 2020, 09:04:29 pm
CATWW - Clock Around the World-Wiser is the name. Is it okay? Or maybe any of you have a better suggestion?
For me it was a simple suggestion , to at least have a working title....

... however....
Quote
The name CATWW makes me think a cat and 2x letter w. So I drew a logo, see the attachment below. Any better idea for the logo?
... you hit the nail there with that awesome logo and now I feel inclined to stick with the name as that logo perfectly matches the name.

Thank you for that.

It really calls out for having that as a clock background, using the whiskers as indicators, just above the nose as middle for the clock-hands  :D

Quote
Can anyone tell me as the original authors of the program (me, JLWest, TRon), can we dual-license it in proprietary and GPL? Is there any GPL's rule that prohibit the original author of the software to dual-license or re-license it to closed software.
Hmz, I do believe the GPL prohibits that. I would have to look into that more closely and get back to that unless someone else has an answer to that.

Same goes for your other questions.
Title: Re: CATWW
Post by: winni on August 24, 2020, 09:22:36 pm
Hi!

And here is the slogan:

"CATWW - The World Wide Cat!"

Winni
Title: Re: CATWW
Post by: lucamar on August 24, 2020, 11:53:38 pm
Quote
Can anyone tell me as the original authors of the program (me, JLWest, TRon), can we dual-license it in proprietary and GPL? Is there any GPL's rule that prohibit the original author of the software to dual-license or re-license it to closed software.
Hmz, I do believe the GPL prohibits that. I would have to look into that more closely and get back to that unless someone else has an answer to that.

Not quite. Nothing can prohibit the original author(s) licensing their work as they see fit so you can dual-license (or triple-license, or quad- or penta-license ;)) if you want.

A different thing is whether it makes sense to do so; for a project that wants to allow both closed and free/open source derivatives I would just select one of the permissive license (say, MIT or 3-clause-bsd, etc.) and leave it at that.

Note that all the used libraries allow this: they all are LGPL with implicit (or explicit) linking exception so having them as a requirement doesn't interfere; that is, in fact, the reason for the existence of the LGPL.
Title: Re: CATWW
Post by: TRon on August 25, 2020, 12:18:23 am
Thank you for your answer lucamar.

Not quite. Nothing can prohibit the original author(s) licensing their work as they see fit so you can dual-license (or triple-license, or quad- or penta-license ;)) if you want.
I was taking (literal) note of what Handoko wrote: Release now as GPL and later decide to make it proprietary. And imho that is something that is in fact prohibited as the GPL clearly states that all changes must be made public again. But I do also believe we need to get into version details of the GPL there, as re-licensing seems allowed starting from v4 ? (https://www.gnu.org/licenses/license-compatibility.html)

Quote
A different thing is whether it makes sense to do so; for a project that wants to allow both closed and free/open source derivatives I would just select one of the permissive license (say, MIT or 3-clause-bsd, etc.) and leave it at that.
I agree to that.

Quote
Note that all the used libraries allow this: they all are LGPL with implicit (or explicit) linking exception so having them as a requirement doesn't interfere; that is, in fact, the reason for the existence of the LGPL.
Thank you for refreshing my memory on LGPL :)

@Handoko:
As I wrote in PM, my only goal is to share. I do not even mind not being an official participant of the project as long as what we present here (as I am contributing) stays open for others to be able to learn from (or put me/us back in place on things what went wrong :D ). I do not care if someone is able to learn enough from it (as that is the whole point) to be able to write his/her own commercial closed source application, even though I prefer the "pay it forward"-thought. Licenses always tend to get in my way of thinking.
Title: Re: CATWW
Post by: TRon on August 25, 2020, 12:53:17 am
CATWW need data for time zone. Does anyone know where can we download the database and use it freely including for closed/commercial projects.
The IANA timezone database data-files are released as public domain. e.g. not restricted by copyright and can be used freely by others.

Having said that, there might be other sources (that I am not ware of).

And here is the slogan:

"CATWW - The World Wide Cat!"
I like it !  :)
Title: Re: CATWW
Post by: winni on August 25, 2020, 01:19:46 am
Hi!

For small applications there is

http://worldtimeapi.org/ (http://worldtimeapi.org/)

They have a API and you can free ask for timezones and daylight savings.
But it is only a little subset of the world.
New Zealand is missing.

Perhaps this is enough.

Winni
Title: Re: CATWW
Post by: JLWest on August 25, 2020, 01:49:34 am
I'm in agreement for most of the discussion. However; I would like the option to allow  CATWW to be used in a commercial product with written permission.

I'm think of someone coming along who would like to use it in a product they sell or one of us wanting to use it in a product.

Maybe handako will come up with a game where he needs a clock or TRon comes up with a commercial program idea. Or just someone contacts us and wants to use it in a commercial product.     
Title: Re: CATWW
Post by: winni on August 25, 2020, 01:57:07 am
Hi!

The clock is 4.000 years old.

And now you want a copyright.
Are we here at Rolex Industries?

Winni
Title: Re: CATWW
Post by: TRon on August 25, 2020, 02:28:37 am
For small applications there is http://worldtimeapi.org/ (http://worldtimeapi.org/)

They have a API and you can free ask for timezones and daylight savings.
That is actually a very nice one. Finally an API that understands what you require and don't force you into expensive subscriptions.

Thank you for that winni.

Quote
But it is only a little subset of the world.
New Zealand is missing.
Huh ?

Code: [Select]
Pacific/Chatham
Pacific/Auckland

afaik those are the two time-zones used in New Zealand.

The clock is 4.000 years old.

And now you want a copyright.
Are we here at Rolex Industries?
LOL

Actually we should file a patent for the workings of the sun, moon and earth.... without them there wouldn't be a need for time to begin with... unless you are a flat-earth believer of course, for those we have a special lamp hanging from the ceiling  :)
Title: Re: CATWW
Post by: lucamar on August 25, 2020, 04:15:14 am
I was taking (literal) note of what Handoko wrote: Release now as GPL and later decide to make it proprietary. And imho that is something that is in fact prohibited as the GPL clearly states that all changes must be made public again.

Yes, but that applies only to licensed users. Authors are not limited in any way (except by contract, as happens in the cultural industry) by what their license to others says. There are plenty of examples out there where the initial license was GPL (or something similar) while the final version(s) were propietary. The usual end-results, of course, are that either the program is forgotten or someone forks the initial FOSS work to keep it open, which is one of the things why it makes little sense. but some people seem to think that it's a good idea ... mostly those that know nothing of the virtues of FOSS. ;)
Title: Re: CATWW
Post by: winni on August 25, 2020, 09:14:49 am

Quote
But it is only a little subset of the world.
New Zealand is missing.
Huh ?

Code: [Select]
Pacific/Chatham
Pacific/Auckland

afaik those are the two time-zones used in New Zealand.



Hi!

Yes the list of timezones is complete.
So Pacific/Auckland is given.
But Auckland as city is missing!

Winni

PS.: Even Wellington as capital is missing.
Title: Re: CATWW
Post by: TRon on August 27, 2020, 05:43:31 pm
Yes, but that applies only to licensed users. Authors are not limited in any way ...
Arrgh. You are right lucamar. I was still looking at it from the other angle  :-[

:facepalm:
Title: Re: CATWW
Post by: TRon on August 27, 2020, 11:18:17 pm
Yes the list of timezones is complete.
Good ! ... You gave me a little scare there  :)

Quote
So Pacific/Auckland is given.
But Auckland as city is missing!

PS.: Even Wellington as capital is missing.
True, and currently also true for catww.

I am working on that part of the program but unfortunately there isn't much progress in that department atm.

Out of curiosity... what would (for you) be an acceptable list of cities (when talking about numbers) ?

Because if wanted I am able to list every parking-lot/shopping-mall that exists in the world but that would require a bit of bandwidth and storage space (over 2GB). But, I could perhaps store that into the exe as a resource ?  :D

So, also there the question is really about the colour of the pasture  ;)

The numbers question is genuine though.... I really have no idea.
Title: Re: CATWW
Post by: JLWest on August 28, 2020, 12:12:46 am
I woul think about 2000 cities. However it would be nice if a person could add the little Holt, Missouri or Lost Rock, Australia.
Title: Re: CATWW
Post by: winni on August 28, 2020, 12:29:51 am
Hi!

Even the producers  of globes have only a rule of thumb:

Fill empty space!
One the one hand they are are happy that there out in the wild near the Russian border in Northern Norway is Kirkenes. Only 5000 inhabitants. But they can draw something in this emptyness.
And on the other hand in the megacities there are medium cities missing: no space ...

I got a CSV base with 11 million geographical entries: Cities, villages, airports, mountain peaks, harbours, historical places, .....

Name UTF8, name ASCII, lat/log, country, timeszone, altitude, inhabitants ....
As you said: 1.3 GB

I would say: As much cities as possible so that a sequential search in a stringlist does not let the user too long wait.  That is around 50.000 entries - from my experience.
To start a DB is a sledgehammer for a little nail

Winni
Title: Re: CATWW
Post by: TRon on August 28, 2020, 01:05:09 am
@winni:
I do believe we are using the same database, or at the least very similar ;)

I would say: As much cities as possible so that a sequential search in a stringlist does not let the user too long wait.  That is around 50.000 entries - from my experience.
To start a DB is a sledgehammer for a little nail
I don't know if using a db would be a sledgehammer. It actually works quite fast and with a bit of thought also reasonably with regards of small memory footprint, but it does require some conversion (which does take up a lot of time).

The conversion/extraction would be required anyway, but could be done beforehand.

It does require some additional details for the city in order to be able to distinguish between them though... Wellington, for instance, being a good example.

I am currently working with a DB of approximately 25.000 cities for testing purpose.
Title: Re: CATWW
Post by: winni on August 28, 2020, 01:48:46 am
Hi!

Mine is no secret: allcities.zip from geonames.org .
Volunteers all around the world and allways growing.

I had too much to work on DBs in my former jobs - I hate them.
And I found an astonishing solution.
I have got a StringGrid with > 70.000 rows and 19 columns.
Quick  like hell. Colum sort in a second.
[QuickSort is Quick!!]
UTF8 search over 19 cols and 70.000 rows in less than a second.
So I don't need a DB

Think about it.

Winni
Title: Re: CATWW
Post by: TRon on August 28, 2020, 05:32:17 pm
Mine is no secret: allcities.zip from geonames.org .
Well, I did not say mine was a secret. It is the same DB  ;)

Quote
Volunteers all around the world and allways growing.
Yes, always growing, always in need for an (easy, painless, smooth) update  ;)

Quote
I have got a StringGrid with > 70.000 rows and 19 columns.
Quick  like hell. Colum sort in a second.
[QuickSort is Quick!!]
UTF8 search over 19 cols and 70.000 rows in less than a second.
So I don't need a DB
Just a quick question. How is filtering working for you ?  ;)

Quote
Think about it.
Oh, but I did  :)

I do not blame you, but you seem to have only a single green pasture that you are looking at ?

Processing of the data for 25.000 entries alone takes about 40-50 seconds at my dark brown coloured pasture.

And.. the thing is slow as f*ck on certain widgetsets/hw. I won't even mention the quirks it has.

And before asking, I am aware of the components that are around in the world and I would like to avoid them. Even more so in case it is possible to solve it in another way, using standard components.

And that is besides the fact that I do not wish to display the data, rather only make it possible for the user to select from a filtered subset (if the user chooses to). So in that case the stringgrid would only serve as a storage space, which seems a bit counter-intuitive to me.

fwiw: I can understand your dislike about db usage.

Just 2 cents.
Title: Re: CATWW
Post by: winni on August 28, 2020, 07:29:24 pm
Hi!

First: Concerning the StringGrid I can talk only about Linux/gtk. No experience how it behaves with other widget sets.

Just made a test with filtering:
Filtered a subset of 102 rows out of 70.000 in 1.5 seconds. The next filterings are always a little bit faster (why??) : 1.2 seconds.

It is important for sorting/searching/filtering that you disable all visual stuff with
BeginUpdate.

Winni

Title: Re: CATWW
Post by: TRon on August 28, 2020, 09:35:46 pm
First: Concerning the StringGrid I can talk only about Linux/gtk. No experience how it behaves with other widget sets.
Even then it depends on where (what hardware) the widget(set) is running  ::)

Quote
Just made a test with filtering:
Filtered a subset of 102 rows out of 70.000 in 1.5 seconds. The next filterings are always a little bit faster (why??) : 1.2 seconds.
hmz, that is indeed a bit strange that you are getting different results on the first run. Have you perhaps constructed your filtering in such a way that it is able to cache ?

Quote
It is important for sorting/searching/filtering that you disable all visual stuff with
BeginUpdate.
Yes, I am aware. Thanks for the reminder  :)

fwiw: I went for a listview in virtual mode, and am still thinking about whether or not a tree-like approach would be more convenient. I'm really tempted to use a virtual treeview. The loading part is really causing the most delay, either when using a string-grid or something else. Although that isn't an issue when using a virtual listview and accessing the data with sqlite.

Does anyone happen to know if there is a class out there that is able to index csv files in such a way that it is able to present the access to the records/fields virtually and is able to actually access/cache them on demand when required ? afaik that would be the only way that could perhaps be faster then stuffing it into a db first.
Title: Re: CATWW
Post by: winni on August 28, 2020, 10:45:27 pm
Hi!

After I found out how to start kernel 5.7 that I could start VirtualBox again. And then Win7.
So I have made some tests with my 70.000 rows CSV file with Win7
At half speed (VirtualBox) !!

Loading the file via LoadFromCSVfile took
3124 milliseconds

Column sort was - like Linux - around 1 second.

So we summarize:
StringGrid is astonishing fast with gtk and Win7.
Dont know about the other widget sets.

That the first of some similar actions is slower than the next ones I also recognized while working with huge graphics. Memory allocation or whatever???

And now I know how to start older kernels.
So it was not useless ....

Winni


Title: Re: CATWW
Post by: JLWest on August 29, 2020, 12:14:21 am
I can test on Windows 10 pro if you need it.
Title: Re: CATWW
Post by: winni on August 29, 2020, 11:08:53 pm
Hi!

Another time arguing for the StringGrid.

I fetched nearly 8000 Airports from  https://openflights.org/data.html
I have put them in a StringGrid.

Then I wrote my own Quicksort for singles (Lat,long).
To sort these 8000 Airports took around 50 milliseconds.

So why should we need a DB???

Winni
Title: Re: CATWW
Post by: TRon on August 31, 2020, 06:38:56 pm
Another time arguing for the StringGrid.

So why should we need a DB???
Don't let me stop you ;)
TinyPortal © 2005-2018