Lemoncode / simplechart

Simplechart seed
MIT License
12 stars 13 forks source link

Create a fake backend (json-server) #22

Closed brauliodiez closed 6 years ago

brauliodiez commented 6 years ago

Just to get focused on the front end on the project early stages let's create a fake backend:

One for the data could be something like (create several entries):

{
  "maps": [
    "id": 1,  
    "title": "Resultado Elecciones Generales 2016 por regiones",
     "type": 1,
     "description": "Lorem ipsum, whatever",
     "tags": ["elecciones", "nacionales", "2016", "regiones"]
     "data": {
        // Data to recreate the map
      } 
  ]
}

One for the api config:

{
  "/api/*": "/$1"
}

Create a custom script step in the package.json file

Later on we will have to refine the "data" internal structure but that's something we can leave for further steps.

ebarriosara commented 6 years ago

Data has been obtained from the following URLs:

In the case of towns and provinces, a single Excel file contains all the data, so it is quicker to get it. However, in the case of regions, it is necessary to manually download the Excel file for each region.

ebarriosara commented 6 years ago

In order to get real data from the Excel file, a Python (v 2.7) script has been created for each type of file (town, province, region or whole country). You can find those scripts and some examples attached parseFiles.zip

Some examples of how to use these scripts are:

The encoding format that has been used is ISO-8859-1 or latin1.

ebarriosara commented 6 years ago

With the information provided as explained in previous comment, the sample db.json structure has been created. It is similar to the schema below:

{ "id": 1, "title": "Resultado Elecciones Generales 2016 por regiones", "type": 1, "description": "...", "tags": [ "elecciones", "nacionales", "2016", "regiones" ], "data": [ { "region": "Andalucía", "provinces": [{ "Nombre de provincia": "Málaga", "results": [ "Party1": { votos: x, diputados: y }, ] },{ provincia: Cádiz, results: [...] }] } ] }, { "id": 2, "title": "Resultado Elecciones Generales 2016 por municipios", "type": 1, "description": "Resultados de las Elecciones Generales de Junio de 2016, por municipios", "tags": [ "elecciones", "nacionales", "2016", "municipios" ], "data": [ { region: Andalucía, provinces: [{ "Nombre de provincia": Málaga, towns: [{ "Nombre de municipio": Estepona, results: [{ "Party1": { votos: 90 } }, { "Party2": { votos: 100 } } ...] }], },{ "Nombre de provincia": Cádiz, towns: [{ "Nombre de municipio": Algeciras, results: [...] }], }] } ] }, { "id": 3, "title": "Resultado Elecciones Generales 2016 por regiones", "type": 1, "description": "Resultados de las Elecciones Generales de Junio de 2016, por Comunidades Autónomas", "tags": [ "elecciones", "nacionales", "2016", "regiones" ], "data": [ {"region": "Andalucía", "results": [{"Party1": {"Diputados": "23", "Votos": "1.426.258"}},...]} ] }

ebarriosara commented 6 years ago

To run json-server, simply use: npm run json-server

In order to see data, you can use:

http://localhost:3000/api/maps?id=1 --> Results by provinces from 2016. http://localhost:3000/api/maps?id=2 --> Results by provinces from 2015. http://localhost:3000/api/maps?id=3 --> Results by towns from 2016. http://localhost:3000/api/maps?id=4 --> Results by regions from 2016. http://localhost:3000/api/maps?id=5 --> Overall results from 2016,

brauliodiez commented 6 years ago

Awesome stuff !!!! just only one thing, could you add the instructions to launch the fake server into the main readme.md?

Just with that instructions is ready to be merged :)

juanbermudezpareja commented 6 years ago

Could it be better to use url's like: http://localhost:3000/api/maps/provinces/2016 instead of the current ones? I say that because I have seen several open data pages, and they have this kind of structure

brauliodiez commented 6 years ago

It's a good idea, right now we have a mock server to go on, but when we start building the real backed defintively we can go for that, on the other hand is hard because we need to add categories.