Giter Club home page Giter Club logo

zuugle-api's Introduction

Zuugle API

First time installation

To install nvm see e.g. https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

Install all modules

Execute in the project directory:

nvm install 20.5.0

nvm use

npm install

and install all dependencies.

Setup database PostgreSQL 16

  1. Install (https://www.docker.com/) on your local machine

  2. Execute these two commands:

    docker build -t zuugle-postgres-db ./

    docker run -d --name zuugle-container -p 5433:5432 zuugle-postgres-db

Setup database connection files

Create a copy of each connection file and rename it. We need four "knexfile*" files in the end.

cp knexfileTourenDb.js.example knexfileTourenDb.js

cp knexfile.js.example knexfile.js

Load data and run backend

Import data locally

npm run build

npm run import-data-full

npm run import-files

Execute backend locally

npm run start

Hint: On local environment using the function logger('anytext'); writes to the file api.logs in your zuugle-api/logs directory. This is helpful, when debugging SQL code, etc.

Follow frontend Readme

Follow the steps described at https://github.com/bahnzumberg/zuugle-suchseite#zuugleat-suchseite

zuugle-api's People

Contributors

cleatuer avatar dependabot[bot] avatar falsal avatar lenaehm avatar martinheppner avatar tobhai avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

zuugle-api's Issues

New columns regular_stops

The table "Fahrplan" has been altered. The folowing columns have been added:

'connection_description_json',
'connection_lastregular_arrival_stop',
'connection_lastregular_arrival_stop_lon',
'connection_lastregular_arrival_stop_lat',
'connection_lastregular_arrival_datetime',
'return_description_json',
'return_firstregular_departure_stop',
'return_firstregular_departure_stop_lon',
'return_firstregular_departure_stop_lat',
'return_firstregular_departure_datetime'

The functionality of the two JSON columns are descibed here: https://github.com/bahnzumberg/hermes/wiki/Connection-and-Return-Description
The JSONs allow us to translate all elements like "Zug" or "Bus", etc.

The others are needed for the itinerary as well.

Please enhance the api towards the surface (suchseite), so we can implement the additional functionality.

Limit query to necessary columns

In Tours.js in line 794 "const query_con = knex('fahrplan').select().where({hashed_url: tour.hashed_url, provider: tour.provider, city_slug: city});" the select should be restricted to the columns, which are really used.

Multi language search backend

Union of three SQLs:

  1. menu_lang: First filters on menu_lang=tours.text_lang and multiply the search weight multiplied with 100
  2. TLD derived: filter on all languages derived from the TLD excluding the one already handled in union 1 (menu_lang). Search_weight multiplied with 10
  3. All the rest: Every language not handled above, will be used in the query now

Over this union, there has to be a query, which is doing the ORDER BY and the LIMIt & OFFSET

Analyse necessity of country_xy columns

What do the columns country_at, country_de, country_de, ... do? They are calculated in the loading process in sync.js. They have been used in the search. Are they used in the frontend?

If not used, please remove columns & code.
If necessary, please document the function in the sync.js file.

authenticate file not working on local environment

On my local machine, if i activate authentication in file authentiate.js i get an axios error (comes from suchseite of course) and white page. (potential fix : axios configuarion ?) .

Main point in this issue:
my local environment works normally without this code , but this file should be checked for the UAT installation, if it is necessary there and if so make sure it is activated in that environment.

Search call/ Bug fix

The call in the client side does not return the expected response (returns empty), while on the BE side , it is producing a whole list of all available tours in the local DB.

Erweiterung um "minimal" API

Bitte neue API "minimal" erstellen. Dieser muss man die folgenden Werte übermitteln, um eine Antwort zu erhalten:

  • key
  • tour_provider
  • tour_id
  • city_slug

Das Resultat ist eine einzelne Zeile, mit den notwendigen Informationen.

Siehe dazu die neu angelegte View: SELECT * FROM zuugle_api.minimal;

npm run import-data-full fails

  1. "p-limit": "^5.0.0", requires ESM.

I was unable to run npm run import-data-full under 20.3.0 or 19.8. The only solution which worked was to downgrade p-limit to 3.1, which doesn't require ESM.

  1. The documentation does not provide any details about TourenDB. Where can I get it?

Data Load leads to white screen

Issue:
conditional rendering using Redux state works only for one of the conditions and not for the other.

Detailed description:
From our Postgres database we pull a value named totalTours through an axios call (see loadTotalTours()), this value we save in a state inside redux store (same name), this works fine but when we do access it (inside Start component) and attempt to conditionally render the Header -depending on the value of totalTours- we get the expected behaviour for a value of >0 but not when the value == 0, for that we get an error (“Rendered fewer hooks than expected. This may be caused by an accidental early return statement.”).

Related Files: (frontend "zuugle_suchseite" repo)
Start/Start.js, Start/Header.js, reducers/tours.js, actions/tourActions.js, actions/types.js, actions/crudActions.js

Autosuggest feature not working without city

Searching for "schnee" gives me autosuggestions - see first picture - when I have selected a city.
The second screenshot shows the same search for "schnee", but shows no auto suggestions.

Image

Image

Is function mergeToursWithFahrplan() still needed?

The function mergeToursWithFahrplan() is doing nothing other than updating the columns country_at, country_de, country_ch, country_it, country_fr and country_si. Is my analysis correct?

If yes, then we should deactivate it completely and remove the columns from the table as well.

Parallelization of syncGPXdata

In sync.js there is the function syncGPXdata. The purpose of the function is to fetch datachunks from the remote "vw_gpx_to_search" and store these into the local table "gpx".

The amount of data is huge. A delta load mechanism is worth thinking about. As a first step the while loop should run in a limited way in parallel. 5 to 10 instances can read and write in parallel without a problem.

export async function syncGPXdata(){
    try {
        await knex.raw(`TRUNCATE gpx;`);
    } catch(err){
        console.log('error: ', err)
    }

    let limit = 5000;
    const query_count = await knexTourenDb('vw_gpx_to_search').count('* as anzahl'); 
    let count_gpx = query_count[0]["anzahl"];
    let count_chunks = round(count_gpx / limit, 0);
    let counter = 0;

    console.log('GPX data count_chunks:', count_chunks)
    console.log('Info: Handling ', count_gpx.toLocaleString("de-de"), ' rows with gpx datapoints.');

    /* The following loop has to be parallised */
    while(counter < count_chunks){
        const result_query = knexTourenDb('vw_gpx_to_search').select('provider', 'hashed_url', 'typ', 'waypoint', 'lat', 'lon', 'ele').whereRaw(`ROUND(lat*lon*10000) % ${count_chunks} = ${counter}`);
        const result = await result_query;
            
        try {
            await knex('gpx').insert([...result]);
        } catch(err){
            console.log('error: ', err)
        }
        counter++;
    }
}

GPX table in PostgreSQL

Change the load so, that the GPX coordinates are stored in a table in the PostgreSQL database. From there the GPX files should be created.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.