thedevsaddam / gojsonq

A simple Go package for querying over JSON, YAML, XML, and CSV data.
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.19k stars 140 forks source link

Custom CSV file, with header on 2 lines #63

Closed xoco70 closed 4 years ago

xoco70 commented 5 years ago

Hi,

I need to parse a csv file that has first general info about data, on 2 lines, and after, a list of measures ( timestamp --> value )

Is it possible to parse it with gojsonq ? I don't really need to query it, accessing all data with a loop is enough for me.

Here is a sample of how the csv begins:

Identifiant PRM;Type de donnees;Date de debut;Date de fin;Grandeur physique;Grandeur metier;Etape metier;Unite;Pas en minutes
23545612340000;Courbe de charge;06/08/2019;08/08/2019;Energie active;Consommation;Comptage Brut;W;
Horodate;Valeur;;;;;;;
2019-08-06T00:30:00+02:00;282;;;;;;;
2019-08-06T01:00:00+02:00;88;;;;;;;
2019-08-06T01:30:00+02:00;124;;;;;;;
2019-08-06T02:00:00+02:00;94;;;;;;;
2019-08-06T02:30:00+02:00;138;;;;;;;
2019-08-06T03:00:00+02:00;94;;;;;;;
2019-08-06T03:30:00+02:00;122;;;;;;;
2019-08-06T04:00:00+02:00;146;;;;;;;
2019-08-06T04:30:00+02:00;184;;;;;;;
2019-08-06T05:00:00+02:00;150;;;;;;;
2019-08-06T05:30:00+02:00;120;;;;;;;

How should I do it ?

redbarron23 commented 5 years ago

why not use CSV here is an example of putting it into a struct https://golangcode.com/how-to-read-a-csv-file-into-a-struct/

On Oct 1, 2019, 9:46 AM -0400, Julien notifications@github.com, wrote:

Hi, I need to parse a csv file that has first general info about data, on 2 lines, and after, a list of measures ( timestamp --> value ) Is it possible to parse it with gojsonq ? I don't really need to query it, accessing all data with a loop is enough for me. Here is a sample of how the csv begins: Identifiant PRM;Type de donnees;Date de debut;Date de fin;Grandeur physique;Grandeur metier;Etape metier;Unite;Pas en minutes 23545612340000;Courbe de charge;06/08/2019;08/08/2019;Energie active;Consommation;Comptage Brut;W; Horodate;Valeur;;;;;;; 2019-08-06T00:30:00+02:00;282;;;;;;; 2019-08-06T01:00:00+02:00;88;;;;;;; 2019-08-06T01:30:00+02:00;124;;;;;;; 2019-08-06T02:00:00+02:00;94;;;;;;; 2019-08-06T02:30:00+02:00;138;;;;;;; 2019-08-06T03:00:00+02:00;94;;;;;;; 2019-08-06T03:30:00+02:00;122;;;;;;; 2019-08-06T04:00:00+02:00;146;;;;;;; 2019-08-06T04:30:00+02:00;184;;;;;;; 2019-08-06T05:00:00+02:00;150;;;;;;; 2019-08-06T05:30:00+02:00;120;;;;;;; How should I do it ? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Kvaz1r commented 5 years ago

There is a sample for it in the Wiki How to use YAML, XML, CSV? But if you not going to use query it have not much sense. There is special packages for reading csv, for example easycsv and csvutil