Re: [Pharo-users] [Pharo-dev] json-server / db.json (lowdb) / faker.js in Pharo/Zinc ?

2020-06-06 Thread Sven Van Caekenberghe
Hi Cédrick,

I think making something like jsonplaceholder would be quite easy.

Do you know about the Zinc-REST package/group ?

It contains an example in its tests, ZnExampleStorageRestServerDelegate with 
unit tests in ZnExampleStorageRestServerDelegateTest which implements a generic 
data storage. Have a look !

BTW, recently I added ZnClient>>#forJsonREST, which uses either STONJSON (which 
is in the image) or NeoJSON (when loaded), so that you can more elegant code 
for this use case:

ZnClient new
  url: 'https://jsonplaceholder.typicode.com/posts';
  forJsonREST;
  get.

ZnClient new
  url: 'https://jsonplaceholder.typicode.com/posts';
  forJsonREST;
  contents: { #title->'Test'. #body->String loremIpsum } asDictionary;
  post.

Sven

> On 6 Jun 2020, at 09:44, Cédrick Béler  wrote:
> 
> Hi Sven and all,
> 
> Disclaimer: just another rather not important query (mainly for fun so don’t 
> hesitate to tell me to use the node packages instead ;-) )
> 
> To show API to students, I sometimes use 
> https://jsonplaceholder.typicode.com. It’s nice to play with client requests. 
> I wonder if this would be interesting to have such tools in Pharo/Zn. Maybe 
> it exists already somehow (for Teapot eventually) ? 
> https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d
> 
> From their GitHub, I discovered json-server + lowdb (based on lowdash) => all 
> nodes packages. 
> https://github.com/typicode.
> 
> 
> 
> It uses a db file db.json and I like such simple « databases ». I know 
> they're not real db.
> https://github.com/typicode/lowdb 
> 
> To me, it could nearly be to me an elegant personal db even if I think this 
> is mostly used to test API’s. 
> Indeed, It’s often used in conjunction with node package faker 
> (https://github.com/marak/Faker.js/ (https://github.com/marak/Faker.js/). 
> I would like to use that to generate static websites from Ecstatic.
> 
> The placeholder default website has limitations. For instance, the following 
> request creates a new post (but then you cannot see the result if you query 
> for posts just after)
> 
> 
> 
> 
> I wanted to go past the limitation of the placeholder site (the db.json 
> cannot be written). I can of course use the node package but you know :)  
> Might be not so straight to port though.
> 
> So there are probably three open questions in this post:
> 1)  lowdb (I know this is not a database but it’s handy and I’d like such 
> usage in static website generation in conjunction with Ecstatic). Any already 
> existing experiments maybe ? I don’t think Voyage can do that.
> 2)  the API json-server based on routes (maybe a job for Teapot) ?
> 3) the faker package as a fun exercice.
> 
> What others think ? My priority would go for having some kind of lowdb (and 
> I’m pretty sure there are experiments around that - It reminds me a bit 
> sandstonedb from Ramon 
> http://onsmalltalk.com/sandstonedb-simple-activerecord-style-persistence-in-squeak.
> 
> Cheers,
> 
> Cédrick
> 
> 
> 




Re: [Pharo-users] [Pharo-dev] json-server / db.json (lowdb) / faker.js in Pharo/Zinc ?

2020-06-06 Thread Cédrick Béler
Hi,

> 
> Hi Cédrick,
> 
> I think making something like jsonplaceholder would be quite easy.
> 
> Do you know about the Zinc-REST package/group ?

I knew but forget about it !

> 
> It contains an example in its tests, ZnExampleStorageRestServerDelegate with 
> unit tests in ZnExampleStorageRestServerDelegateTest which implements a 
> generic data storage. Have a look !

Will definitely look again at it. Is it using a json file as db too ? I guess 
that be easy to add if not. I’ll look at it soon.

Any feedback about faker ? That’d be a fun project to do in Pharo.
There are lots of them. I don’t know which one to look at more in detail (js, 
ruby, python, php... ?).
https://github.com/faker-ruby/faker
https://github.com/marak/Faker.js/
https://github.com/joke2k/faker 
…

Anybody knows what’s the most « complete » or elegant ?


> 
> BTW, recently I added ZnClient>>#forJsonREST, which uses either STONJSON 
> (which is in the image) or NeoJSON (when loaded), so that you can more 
> elegant code for this use case:


Uhm right, I always forget and use the old way (with #contentReader: ).


Thanks for the information Sven,

Cédrick



> 
> ZnClient new
>  url: 'https://jsonplaceholder.typicode.com/posts';
>  forJsonREST;
>  get.
>   
> ZnClient new
>  url: 'https://jsonplaceholder.typicode.com/posts';
>  forJsonREST;
>  contents: { #title->'Test'. #body->String loremIpsum } asDictionary;
>  post.
> 
> Sven
> 
>> On 6 Jun 2020, at 09:44, Cédrick Béler  wrote:
>> 
>> Hi Sven and all,
>> 
>> Disclaimer: just another rather not important query (mainly for fun so don’t 
>> hesitate to tell me to use the node packages instead ;-) )
>> 
>> To show API to students, I sometimes use 
>> https://jsonplaceholder.typicode.com. It’s nice to play with client 
>> requests. I wonder if this would be interesting to have such tools in 
>> Pharo/Zn. Maybe it exists already somehow (for Teapot eventually) ? 
>> https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d
>> 
>> From their GitHub, I discovered json-server + lowdb (based on lowdash) => 
>> all nodes packages. 
>> https://github.com/typicode.
>> 
>> 
>> 
>> It uses a db file db.json and I like such simple « databases ». I know 
>> they're not real db.
>> https://github.com/typicode/lowdb 
>> 
>> To me, it could nearly be to me an elegant personal db even if I think this 
>> is mostly used to test API’s. 
>> Indeed, It’s often used in conjunction with node package faker 
>> (https://github.com/marak/Faker.js/ (https://github.com/marak/Faker.js/). 
>> I would like to use that to generate static websites from Ecstatic.
>> 
>> The placeholder default website has limitations. For instance, the following 
>> request creates a new post (but then you cannot see the result if you query 
>> for posts just after)
>> 
>> 
>> 
>> 
>> I wanted to go past the limitation of the placeholder site (the db.json 
>> cannot be written). I can of course use the node package but you know :)  
>> Might be not so straight to port though.
>> 
>> So there are probably three open questions in this post:
>> 1)  lowdb (I know this is not a database but it’s handy and I’d like such 
>> usage in static website generation in conjunction with Ecstatic). Any 
>> already existing experiments maybe ? I don’t think Voyage can do that.
>> 2)  the API json-server based on routes (maybe a job for Teapot) ?
>> 3) the faker package as a fun exercice.
>> 
>> What others think ? My priority would go for having some kind of lowdb (and 
>> I’m pretty sure there are experiments around that - It reminds me a bit 
>> sandstonedb from Ramon 
>> http://onsmalltalk.com/sandstonedb-simple-activerecord-style-persistence-in-squeak.
>> 
>> Cheers,
>> 
>> Cédrick
>> 
>> 
>> 
> 
> 



Re: [Pharo-users] shape file reading

2020-06-06 Thread Hernán Morales Durand
Done!

Cheers

Hernán

El sáb., 6 jun. 2020 a las 3:17, Stéphane Ducasse (<
stephane.duca...@inria.fr>) escribió:

> Please add this to the readme :)
>
>
> On 5 Jun 2020, at 23:19, Hernán Morales Durand 
> wrote:
>
>
>
> El vie., 5 jun. 2020 a las 9:27, Baveco, Hans ()
> escribió:
>
>> Well, it appears that simple direct downloading does not download the
>> real shapefile. Taking care to actually get a shapefile, the result loads
>> without problems.
>>
>> ne_110m_populated_places.shp is a PointShape with 243 shapes (points). If
>> you display it on a Form (#displayMorphic) you won’t see much (243 hardly
>> visible dots).
>>
>>
>>
>
> I checked and my previous download method was completely wrong. Now
> switching from ZnEasy to ZnClient to download and it works nicely:
>
>  | shpE legend urlRoot urlESRIFilePrefix urlESRIFileShp urlPath response
> fileRef |
>
> " Download Shapefile resources "
> urlRoot := '
> https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/
> '.
> urlESRIFilePrefix := 'ne_110m_populated_places'.
> urlESRIFileShp := urlESRIFilePrefix , '.shp'.
> urlPath := urlRoot , urlESRIFilePrefix.
>
> #('.shx' '.dbf' '.shp' '.cpg' '.prj') do: [ : ext |
>   ZnClient new
>url: (urlPath , ext) asZnUrl;
>queryAt: 'raw' put: 'true';
>numberOfRetries: 2;
>enforceHttpSuccess: true;
>downloadTo: urlESRIFilePrefix , ext;
>get ].
>
> " Load and display it in Morphic "
> shpE := ShapeEnsemble fromFile: urlESRIFileShp.
> " List data fields "
> shpE dataFields inspect.
> " List all shape records "
> shpE shapeRecords inspect.
> " Set the current attribute "
> shpE attribute: 'NAME'.
>
> legend := ColorLegend mapValuesToRandom: shpE valuesOfCurrentAttribute.
> shpE legend: legend.
>
> shpE displayMorphic.
>
>
>> With an application for vector graphics (Roassal?) that can read &
>> display the vector data we would get much nicer maps...
>>
>>
>>
>> Hans
>>
>>
>>
>> *From:* Baveco, Hans 
>> *Sent:* vrijdag 5 juni 2020 12:44
>> *To:* Any question about pharo is welcome 
>> *Subject:* [Pharo-users] shape file reading
>>
>>
>>
>> Hi Hernan
>>
>>
>>
>> I downloaded this shapefile directly via the browser. Indeed it won’t
>> load, the type of shape file returned is
>>
>> self longAt: 33 bigEndian: false -> 577660194
>>
>>
>>
>>
>>
>> where it should have answered an Integer between 0 and 31
>>
>>
>>
>> shapeType
>>
>>  "position 32, Integer between 0 and 31, Little Endian"
>>
>>
>>
>>  ^shpBytes longAt: 33 bigEndian: false
>>
>>
>>
>>
>>
>> No idea what could be the cause – apparently the header of the file (the
>> first 100 bytes) is not ok...
>>
>>
>>
>> Hans
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> You mean some types are missing? Because I get this error when I try to
>> read some SHP files: "Types > 20 are not yet accounted for"
>>
>>
>>
>> I wrote this script to reproduce:
>>
>>
>>
>>  | shpE legend urlRoot urlESRIFilePrefix urlESRIFileShp urlPath response
>> fileRef |
>>
>> " Download Shapefile resources "
>> urlRoot := '
>> https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/
>> '.
>> urlESRIFilePrefix := 'ne_110m_populated_places'.
>> urlESRIFileShp := urlESRIFilePrefix , '.shp'.
>> urlPath := urlRoot , urlESRIFilePrefix.
>>
>> #('.shx' '.dbf' '.shp') do: [ : ext |
>> | url |
>> url :=  (urlPath , ext , '?raw=true') asZnUrl.
>> (response := ZnEasy get: url) isSuccess
>> ifFalse: [ self error: 'Cannot download file' ].
>> fileRef := FileSystem disk workingDirectory / (urlESRIFilePrefix , ext).
>> fileRef writeStreamDo: [ : stream |
>> stream nextPutAll: ((ZnByteEncoder newForEncoding: 'koi8r') decodeBytes:
>> response contents ) ] ].
>>
>>
>>
>> Once downloaded:
>>
>>
>>
>> | urlESRIFilePrefix urlESRIFileShp shpE |
>> urlESRIFilePrefix := 'ne_110m_populated_places'.
>> urlESRIFileShp := urlESRIFilePrefix , '.shp'.
>>
>> " Load and display it in Morphic "
>> shpE := ShapeEnsemble fromFile: urlESRIFileShp.
>>
>>
>>
>> Maybe it's related with the fact they are encoded as koi8r?
>>
>> I checked with Zinc downloading first from the browser:
>>
>>
>>
>> | shpFile |
>>
>> shpFile := 'ne_110m_admin_0_countries.shp' asFileReference.
>> [ shpFile binaryReadStreamDo: [ : in |
>> (ZnCharacterEncoder detectEncoding: in upToEnd)
>> identifier ] ]
>> on: ZnCharacterEncodingError
>> do: [ nil ].
>>
>>
>>
>>
>>
>> Cheers,
>>
>>
>>
>> Hernán
>>
>>
>>
>>
>>
>>
> 
> Stéphane Ducasse
> http://stephane.ducasse.free.fr / http://www.pharo.org
> 03 59 35 87 52
> Assistant: Aurore Dalle
> FAX 03 59 57 78 50
> TEL 03 59 35 86 16
> S. Ducasse - Inria
> 40, avenue Halley,
> Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
> Villeneuve d'Ascq 59650
> France
>
>


[Pharo-users] Roassal 0.9.1 is out!

2020-06-06 Thread Alexandre Bergel via Pharo-users
--- Begin Message ---
Hello,

Roassal3 is an agile visualization engine for Pharo 8 and Pharo 9. Roassal is 
made to visualize data in an interactive way data. The GitHub website is 
https://github.com/ObjectProfile/Roassal3 

It contains tutorials and many documentations.

We are happy to announce a new version of Roassal3, 0.9.1. Here is a summary of 
the release description:
-=-=-=-=-=-=
This version 0.9.1 improves Roassal3 in many different aspects. Here are the 
most relevants:

• A lot of class and method comments
• Improvement of the animation capabilities
• Improvement of Chart, the charting library
• Better highlighting mechanism
• Added some tests that check for the dependencies of Roassal3, just to 
make sure we do not introduce an unwanted dependency
• Improvement of the popup
• Better search in canvas capabilities
• Improvement of the force based layout
• Improvement of the stroke lines
• Many many more bugs fixes and small improvements...
-=-=-=-=-=-=

We would to thank everybody for making this to happen. You truly Rock!

Cheers,
Alexandre

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



--- End Message ---