Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheppner committed Sep 2, 2024
2 parents 25b682a + 0dd665a commit 89d5599
Show file tree
Hide file tree
Showing 117 changed files with 63 additions and 887 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ public/gpx-image/*/*.webp
public/gpx-image-with-track/*.jpg
public/gpx-track/totour/*/*.gpx
public/gpx-track/fromtour/*/*.gpx
public/range-image/desktop.ini
public/range-image/*.jpg
package-lock.json
src/firebase.json
src/knexfile.js
src/knexfileTourenDb.js
.DS_Store
.local-chromium
api.log
test.json
test.json
*Zone.Identifier
34 changes: 8 additions & 26 deletions database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -235,29 +235,11 @@ CREATE TABLE tracks (
);




-- 30.03.2024 & 26.04.2024 run this drop columns if you have an existing database
ALTER TABLE fahrplan
DROP COLUMN IF EXISTS connection_description,
DROP COLUMN IF EXISTS connection_description_detail,
DROP COLUMN IF EXISTS return_description,
DROP COLUMN IF EXISTS return_description_detail,
DROP COLUMN IF EXISTS connection_lastregular_arrival_stop,
DROP COLUMN IF EXISTS connection_lastregular_arrival_stop_lon,
DROP COLUMN IF EXISTS connection_lastregular_arrival_stop_lat,
DROP COLUMN IF EXISTS connection_departure_stop,
DROP COLUMN IF EXISTS connection_departure_stop_lon,
DROP COLUMN IF EXISTS connection_departure_stop_lat,
DROP COLUMN IF EXISTS connection_arrival_stop,
DROP COLUMN IF EXISTS connection_arrival_stop_lon,
DROP COLUMN IF EXISTS connection_arrival_stop_lat,
DROP COLUMN IF EXISTS connection_returns_departure_stop,
DROP COLUMN IF EXISTS return_departure_stop_lon,
DROP COLUMN IF EXISTS return_departure_stop_lat,
DROP COLUMN IF EXISTS return_firstregular_departure_stop,
DROP COLUMN IF EXISTS return_firstregular_departure_stop_lon,
DROP COLUMN IF EXISTS return_firstregular_departure_stop_lat,
DROP COLUMN IF EXISTS return_arrival_stop,
DROP COLUMN IF EXISTS return_arrival_stop_lon,
DROP COLUMN IF EXISTS return_arrival_stop_lat;
CREATE TABLE canonical_alternate (
id SERIAL,
city_slug varchar(64) NOT NULL,
canonical_yn char(1) DEFAULT 'n',
zuugle_url varchar(100) NOT NULL,
href_lang varchar(5) DEFAULT 'de-at',
PRIMARY KEY (id, city_slug)
);
Binary file removed public/range-image/adula-alpen-winter.jpg
Binary file not shown.
Binary file removed public/range-image/adula-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/albula-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/allgaeuer-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/alpenvorland.jpg
Binary file not shown.
Binary file removed public/range-image/ammergauer-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/ankogelgruppe.jpg
Binary file not shown.
Binary file removed public/range-image/appenzeller-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/austria.jpg
Binary file not shown.
Binary file removed public/range-image/bayerische-voralpen.jpg
Binary file not shown.
Binary file removed public/range-image/bayerischer-wald.jpg
Binary file not shown.
Binary file removed public/range-image/belledonne.jpg
Binary file not shown.
Binary file removed public/range-image/berchtesgadener-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/berner-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/bernina-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/boehmerwald.jpg
Binary file not shown.
Binary file removed public/range-image/brandenberger-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/bregenzerwaldgebirge.jpg
Binary file not shown.
Binary file removed public/range-image/chiemgauer-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/dachsteingebirge.jpg
Binary file not shown.
Binary file removed public/range-image/default-orig.jpg
Binary file not shown.
Binary file removed public/range-image/default.jpg
Binary file not shown.
Binary file removed public/range-image/dinarisches-gebirge.jpg
Binary file not shown.
Binary file removed public/range-image/dolomiten.jpg
Binary file not shown.
Binary file removed public/range-image/ennstaler-alpen.jpg
Binary file not shown.
Binary file removed public/range-image/frankreich.jpg
Diff not rendered.
Binary file removed public/range-image/freiburger-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/gailtaler-alpen.jpg
Diff not rendered.
Binary file added public/range-image/gardasee.webp
Binary file not shown.
Binary file removed public/range-image/germany.jpg
Diff not rendered.
Binary file removed public/range-image/glocknergruppe.jpg
Diff not rendered.
Binary file removed public/range-image/goldberggruppe.jpg
Diff not rendered.
Binary file removed public/range-image/gotthard-gruppe-winter.jpg
Diff not rendered.
Binary file removed public/range-image/gotthard-gruppe.jpg
Diff not rendered.
Binary file removed public/range-image/granatspitzgruppe.jpg
Diff not rendered.
Binary file removed public/range-image/gurktaler-alpen-nockberge.jpg
Diff not rendered.
Binary file removed public/range-image/gutensteiner-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/hausruck.jpg
Diff not rendered.
Binary file removed public/range-image/hochschwabgruppe.jpg
Diff not rendered.
Binary file removed public/range-image/italien.jpg
Diff not rendered.
Binary file removed public/range-image/julische-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/jura.jpg
Diff not rendered.
Binary file removed public/range-image/kaisergebirge.jpg
Diff not rendered.
Binary file added public/range-image/kanton-jura.webp
Binary file not shown.
Binary file removed public/range-image/karawanken-bachergebirge.jpg
Diff not rendered.
Binary file removed public/range-image/karnischer-hauptkamm.jpg
Diff not rendered.
Binary file removed public/range-image/karpaten.jpg
Diff not rendered.
Binary file removed public/range-image/karwendel.jpg
Diff not rendered.
Binary file removed public/range-image/kitzbueheler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/kreuzeckgruppe.jpg
Diff not rendered.
Binary file removed public/range-image/lavanttaler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/lechquellengebirge.jpg
Diff not rendered.
Binary file removed public/range-image/lechtaler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/leone-gruppe.jpg
Diff not rendered.
Binary file added public/range-image/ligurische-alpen.jpg.webp
Binary file not shown.
Binary file removed public/range-image/livigno-alpen.jpg
Diff not rendered.
Diff not rendered.
Binary file removed public/range-image/mangfallgebirge.jpg
Diff not rendered.
Binary file removed public/range-image/mont-blanc-gruppe.jpg
Diff not rendered.
Binary file removed public/range-image/muehlviertel.jpg
Diff not rendered.
Binary file removed public/range-image/muerzsteger-alpen.jpg
Diff not rendered.
Binary file not shown.
Binary file removed public/range-image/null.jpg
Diff not rendered.
Binary file removed public/range-image/oberoesterreichische-voralpen.jpg
Diff not rendered.
Binary file removed public/range-image/oetztaler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/ortlergruppe.jpg
Diff not rendered.
Binary file removed public/range-image/radstaedter-tauern.jpg
Diff not rendered.
Binary file removed public/range-image/raetikon.jpg
Diff not rendered.
Binary file removed public/range-image/randgebirge-oestlich-der-mur.jpg
Diff not rendered.
Binary file removed public/range-image/rax-schneeberg-gruppe.jpg
Diff not rendered.
Binary file removed public/range-image/rieserfernergruppe.jpg
Diff not rendered.
Diff not rendered.
Binary file removed public/range-image/salzburger-schieferalpen.jpg
Diff not rendered.
Binary file removed public/range-image/salzkammergut-berge.jpg
Diff not rendered.
Binary file removed public/range-image/samnaungruppe.jpg
Diff not rendered.
Binary file removed public/range-image/sarntaler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/schladminger-tauern.jpg
Diff not rendered.
Binary file removed public/range-image/schobergruppe.jpg
Diff not rendered.
Binary file removed public/range-image/schweiz.jpg
Diff not rendered.
Binary file removed public/range-image/schweizer-mittelland.jpg
Diff not rendered.
Binary file removed public/range-image/seckauer-tauern.jpg
Diff not rendered.
Binary file removed public/range-image/see-alpen-meeralpen.jpg
Diff not rendered.
Binary file removed public/range-image/sengsengebirge.jpg
Diff not rendered.
Binary file removed public/range-image/silvretta.jpg
Diff not rendered.
Binary file removed public/range-image/slowakei.jpg
Diff not rendered.
Binary file removed public/range-image/slowenien.jpg
Diff not rendered.
Binary file removed public/range-image/steiner-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/stubaier-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/tambogruppe.jpg
Diff not rendered.
Binary file removed public/range-image/tennengebirge.jpg
Diff not rendered.
Binary file removed public/range-image/totes-gebirge.jpg
Diff not rendered.
Binary file removed public/range-image/tschechien.jpg
Diff not rendered.
Binary file removed public/range-image/tuernitzer-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/tuxer-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/ungarn.jpg
Diff not rendered.
Binary file removed public/range-image/vanoise.jpg
Diff not rendered.
Binary file removed public/range-image/venedigergruppe.jpg
Diff not rendered.
Binary file removed public/range-image/verwall.jpg
Diff not rendered.
Binary file removed public/range-image/villgratner-berge.jpg
Diff not rendered.
Binary file removed public/range-image/waldviertel.jpg
Diff not rendered.
Binary file removed public/range-image/walliser-alpen-winter.jpg
Diff not rendered.
Binary file removed public/range-image/walliser-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/wetterstein-mieminger-gebirge.jpg
Diff not rendered.
Binary file removed public/range-image/wien.jpg
Diff not rendered.
Binary file removed public/range-image/wienerwald.jpg
Diff not rendered.
Binary file removed public/range-image/ybbstaler-alpen.jpg
Diff not rendered.
Binary file removed public/range-image/zillertaler-alpen.jpg
Diff not rendered.
29 changes: 29 additions & 0 deletions src/jobs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,35 @@ export async function fixTours(){
WHERE ct.tour_id=e.tour_id
AND ct.city_slug=e.city_slug;`);


// fill information about canonical and alternate links
await knex.raw(`TRUNCATE canonical_alternate;`);
await knex.raw(`INSERT INTO canonical_alternate (id, city_slug, canonical_yn, zuugle_url, href_lang)
SELECT
tour_id,
city_slug,
CASE WHEN ranking=1 THEN 'y' ELSE 'n' END AS canonical_yn,
zuugle_url,
hreflang
FROM (
SELECT
RANK() OVER(PARTITION BY c2t.tour_id ORDER BY c2t.min_connection_no_of_transfers ASC, c2t.min_connection_duration ASC, c2t.stop_selector DESC, c2t.city_slug ASC) AS ranking,
c2t.tour_id,
c2t.city_slug,
CONCAT('www.zuugle.', LOWER(c2t.reachable_from_country), '/tour/', c2t.tour_id, '/', c2t.city_slug) AS zuugle_url,
CASE WHEN c2t.reachable_from_country='SI' THEN 'sl-si'
WHEN c2t.reachable_from_country='DE' THEN 'de-de'
WHEN c2t.reachable_from_country='IT' THEN 'it-it'
WHEN c2t.reachable_from_country='CH' THEN 'de-ch'
WHEN c2t.reachable_from_country='LI' THEN 'de-li'
WHEN c2t.reachable_from_country='FR' THEN 'fr-fr'
ELSE 'de-at' END AS hreflang
FROM city2tour AS c2t
INNER JOIN tour AS t
ON t.id=c2t.tour_id
) AS a;`);


// Delete all the entries from logsearchphrase, which are older than 360 days.
await knex.raw(`DELETE FROM logsearchphrase WHERE search_time < NOW() - INTERVAL '360 days';`);

Expand Down
84 changes: 20 additions & 64 deletions src/routes/tours.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ router.get('/map', (req, res) => mapWrapper(req, res));
router.get('/provider/:provider', (req, res) => providerWrapper(req, res));

router.get('/total', (req, res) => totalWrapper(req, res));
// router.get('/gpx', (req, res) => gpxWrapper(req, res));
router.get('/:id/connections', (req, res) => connectionsWrapper(req, res));
router.get('/:id/connections-extended', (req, res) => connectionsExtendedWrapper(req, res));
router.get('/:id/gpx', (req, res) => tourGpxWrapper(req, res));
router.get('/:id/:city', (req, res) => getWrapper(req, res));
Expand Down Expand Up @@ -566,7 +564,7 @@ const listWrapper = async (req, res) => {

// markers-related
if (!!markers_result && !!markers_result.rows) {
markers_array = markers_result.rows; // This is to be passed to the response below
markers_array = markers_result.rows; // This is to be passed to the response below
} else {
console.log("markers_result is null or undefined");
}
Expand Down Expand Up @@ -889,63 +887,6 @@ const filterWrapper = async (req, res) => {



const connectionsWrapper = async (req, res) => {
const id = req.params.id;
const city = !!req.query.city ? req.query.city : !!req.params.city ? req.params.city : null;
const domain = req.query.domain;

const weekday = getWeekday(moment());
const tour = await knex('tour').select().where({id: id}).first();
if(!!!tour || !!!city){
res.status(404).json({success: false});
return;
}

// const query_con = knex('fahrplan').select().where({hashed_url: tour.hashed_url, city_slug: city});
// const connections = await query_con;

let connections = [];
const fahrplan_sql = `SELECT * FROM fahrplan WHERE hashed_url='${tour.hashed_url}' AND city_slug='${city}';`;
const fahrplan_result = await knex.raw(fahrplan_sql)
if (!!fahrplan_result && !!fahrplan_result.rows) {
connections = fahrplan_result.rows;
}

let missing_days = getMissingConnectionDays(connections);

await Promise.all(connections.map(connection => new Promise(resolve => {
connection.best_connection_duration_minutes = minutesFromMoment( moment(connection.best_connection_duration, 'HH:mm:ss') );
connection.connection_duration_minutes = minutesFromMoment( moment(connection.connection_duration, 'HH:mm:ss') );
connection.return_duration_minutes = minutesFromMoment( moment(connection.return_duration, 'HH:mm:ss') );
connection.missing_days = missing_days;
resolve(connection);
})));


let filteredConnections = [];
connections.forEach(t => {
if(!!!filteredConnections.find(tt => compareConnections(t, tt))){
filteredConnections.push(t);
}
})

let filteredReturns = [];
getConnectionsByWeekday(connections, weekday).forEach(t => {
/** Die Rückreisen werden nach aktuellem Tag gefiltert -> kann man machen, muss man aber nicht. Wenn nicht gefiltert, werden alle Rückreisen für alle Wochentage angezeigt, was eine falsche Anzahl an Rückreisen ausgibt */
if(!!!filteredReturns.find(tt => compareConnectionReturns(t, tt))){
t.gpx_file = `${getHost(domain)}/public/gpx-track/fromtour/${last_two_characters(t.fromtour_track_key)}/${t.fromtour_track_key}.gpx`;

filteredReturns.push(t);
}
})

filteredReturns.sort(function(x, y){
return moment(x.return_departure_datetime).unix() - moment(y.return_departure_datetime).unix();
})

res.status(200).json({success: true, connections: filteredConnections, returns: filteredReturns});
}

const connectionsExtendedWrapper = async (req, res) => {
const id = req.params.id;
const city = !!req.query.city ? req.query.city : !!req.params.city ? req.params.city : null;
Expand Down Expand Up @@ -1172,18 +1113,19 @@ const getConnectionsByWeekday = (connections, weekday) => {
const prepareTourEntry = async (entry, city, domain, addDetails = true) => {
if( !(!!entry && !!entry.provider) ) return entry ;

entry.gpx_file = `${getHost(domain)}/public/gpx/${last_two_characters(entry.id)}/${entry.id}.gpx`;
const host = getHost(domain);
entry.gpx_file = `${host}/public/gpx/${last_two_characters(entry.id)}/${entry.id}.gpx`;

if(!!addDetails){
if(!!city){
const toTour = await knex('fahrplan').select('totour_track_key').where({hashed_url: entry.hashed_url, city_slug: city}).whereNotNull('totour_track_key').first();
const fromTour = await knex('fahrplan').select('fromtour_track_key').where({hashed_url: entry.hashed_url, city_slug: city}).whereNotNull('fromtour_track_key').first();

if(!!toTour && !!toTour.totour_track_key){
entry.totour_gpx_file = `${getHost(domain)}/public/gpx-track/totour/${last_two_characters(toTour.totour_track_key)}/${toTour.totour_track_key}.gpx`;
entry.totour_gpx_file = `${host}/public/gpx-track/totour/${last_two_characters(toTour.totour_track_key)}/${toTour.totour_track_key}.gpx`;
}
if(!!fromTour && !!fromTour.fromtour_track_key){
entry.fromtour_gpx_file = `${getHost(domain)}/public/gpx-track/fromtour/${last_two_characters(fromTour.fromtour_track_key)}/${fromTour.fromtour_track_key}.gpx`;
entry.fromtour_gpx_file = `${host}/public/gpx-track/fromtour/${last_two_characters(fromTour.fromtour_track_key)}/${fromTour.fromtour_track_key}.gpx`;
}
}

Expand All @@ -1193,10 +1135,24 @@ const prepareTourEntry = async (entry, city, domain, addDetails = true) => {

// convert the "difficulty" value into a text value
entry.difficulty = convertDifficulty(entry.difficulty)


// add info about canonical and alternate links of this tour with entry.id
const canon_sql = `SELECT
city_slug,
canonical_yn,
zuugle_url,
href_lang
FROM canonical_alternate
WHERE id=${entry.id};`;
const canonical = await knex.raw(canon_sql);
if (!!canonical) {
entry.canonical = canonical.rows;
}
}

const { ["hashed_url"]: remove, ...rest } = entry;
return rest;
}

export default router;
export default router;
7 changes: 0 additions & 7 deletions src/utils/constants.js

This file was deleted.

Loading

0 comments on commit 89d5599

Please sign in to comment.