githut icon indicating copy to clipboard operation
githut copied to clipboard

Add buttons, zip, and csv files to be downloaded

Open JeremyLARDENOIS opened this issue 4 years ago • 12 comments

Closes #57

JeremyLARDENOIS avatar Apr 20 '22 08:04 JeremyLARDENOIS

Two ways to generate CSV and zip files. One by launching convert_data.js (work if .json are present), the other in query.js (not tested) The downloading of zip file doesn't work. I don't know what URI I need to use. I also didn't added data zipped and data in csv, but I can add them if you want.

JeremyLARDENOIS avatar Apr 20 '22 08:04 JeremyLARDENOIS

Thanks for your effort. Would it be possible to generate csv and zip files on-the-fly when you press the download button without pushing it to the server (to put it in git)?

madnight avatar Apr 20 '22 10:04 madnight

Maybe I didn't understand, but I think that generating a new zip file each time that someone clicks on "Download" is a bad idea if JSON files are not dynamic and uploaded manually. Instead, we can launch the convert_data.js script. If they are dynamic and loaded each time that someone connects on the website, I can generate zip and CSV files on-the-fly.

JeremyLARDENOIS avatar Apr 20 '22 12:04 JeremyLARDENOIS

The json files are currently not dynamic, but I can think of a future feature like download the json or csv only for a few selected languages. We already have the possibility to filter languages in the chart and to share a URL with pre-selected languages. So in this case it would be better to generate the csv and zip file on-the-fly, when a user hits the download button. Another reason is that I want to avoid to commit zip files into git. We already have a single source of truth, that's the json files, all other formats could be converted dynamically. This way it's also not possible to get inconsistent datasets (e.g. different values in csv vs json).

madnight avatar Apr 20 '22 13:04 madnight

I understand the problem of consistency. Two choices are possible from my mind:

  • Generate on the fly the file that asks the user for each file request
  • Generate files one time by Github actions

JeremyLARDENOIS avatar Apr 21 '22 09:04 JeremyLARDENOIS

If possible, e.g. it doesn't take too much time, then I would prefer to generate the csv and zip on-the-fly as soon as the user hits the download button. If it takes more than let's say 10 seconds to generate these files, then I would prefer GitHub actions.

madnight avatar Apr 21 '22 11:04 madnight

I think it's ok to generate it on-the-fly so :smile:

$ time node convert_data.js 
real	0m0,124s
user	0m0,121s
sys	0m0,026s

JeremyLARDENOIS avatar Apr 21 '22 11:04 JeremyLARDENOIS

Just, what do I do if the file exists?

JeremyLARDENOIS avatar Apr 22 '22 10:04 JeremyLARDENOIS

Could you elaborate?

madnight avatar Apr 22 '22 10:04 madnight

Yes, I will try. I don't know if JSON files are sent to the client/navigator but if they aren't, that means that the conversion needs to be made on the server-side. If it is, the question is should I launch a generating or not if files CSV or zip are already generated? And if yes, how can I handle the fact that two users ask for files at the same time?

JeremyLARDENOIS avatar Apr 22 '22 10:04 JeremyLARDENOIS

Isn't it possible to convert json to csv clientside only? So user hits the download button, fetch(json_url) -> store as blob -> convert to csv -> start download, something like this:

https://stackoverflow.com/a/63965930

madnight avatar Apr 24 '22 06:04 madnight

It could be possible if JSON files were exposed. I don't know how to expose them.

JeremyLARDENOIS avatar Apr 24 '22 14:04 JeremyLARDENOIS

@madnight Hi, I'm back ! (sorry for the delay) . I wanted to try to launch the project and i didn't achieve when I did the yarn install and npm run dev command, I caught an error, maybe due to node version, what is the node version that you support ?

JeremyLARDENOIS avatar Nov 21 '22 12:11 JeremyLARDENOIS

Welcome back,

I develop under Arch Linux which has quite recent node versions. Have you tried "yarn dev" instead of "npm run dev"? Can you provide the error message?

madnight avatar Nov 21 '22 19:11 madnight

I did a yarn dev but I got the same error message

Starting the development server...

/home/jerem/projects/githut/node_modules/react-scripts/scripts/start.js:19
  throw err;
  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:140:10)
    at module.exports (/home/jerem/projects/githut/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/home/jerem/projects/githut/node_modules/webpack/lib/NormalModule.js:417:16)
    at /home/jerem/projects/githut/node_modules/webpack/lib/NormalModule.js:452:10
    at /home/jerem/projects/githut/node_modules/webpack/lib/NormalModule.js:323:13
    at /home/jerem/projects/githut/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /home/jerem/projects/githut/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/home/jerem/projects/githut/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /home/jerem/projects/githut/node_modules/react-scripts/node_modules/babel-loader/lib/index.js:59:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v19.1.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Can you tell me the result of your node --version ?

JeremyLARDENOIS avatar Nov 22 '22 09:11 JeremyLARDENOIS

Node 16

madnight avatar Nov 22 '22 20:11 madnight

it works on node 16, maybe it could be cool to be specified. I will finish this PR so :)

JeremyLARDENOIS avatar Nov 23 '22 10:11 JeremyLARDENOIS

Hello, I went to finished and rebase, I think that all is ready. Let me know if there is something wrong, if you want to add something else or if you have any questions

JeremyLARDENOIS avatar Dec 06 '22 10:12 JeremyLARDENOIS

@madnight still up ?

JeremyLARDENOIS avatar Dec 12 '22 12:12 JeremyLARDENOIS

Merged

madnight avatar Dec 12 '22 20:12 madnight

Thanks for your work. I moved the button below the table for aesthetical reasons.

madnight avatar Dec 12 '22 20:12 madnight

There is no problem. Was cool to contribute to this helpful project :)

JeremyLARDENOIS avatar Dec 13 '22 12:12 JeremyLARDENOIS