Skip to content

Commit 85b989b

Browse files
committed
Add path to trip CRUD operations
1 parent 988abb4 commit 85b989b

36 files changed

+398
-138
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ start-local: start-db
2424

2525
# run trip sync + comparison
2626
sync-trips:
27-
env $(cat .env | xargs) POSTGRES_HOST=localhost python -c "from src.db_sync import sync_db_from_sqlite; sync_db_from_sqlite()"
27+
env $$(cat .env | xargs) POSTGRES_HOST=localhost python -c "from src.db_sync import sync_db_from_sqlite; sync_db_from_sqlite()"
2828

2929
# stop all containers
3030
stop:

app.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from io import BytesIO, StringIO
2929
from shapely.geometry import shape, mapping
3030
from shapely.ops import unary_union
31+
from pathlib import Path as osPath
3132

3233
import distinctipy
3334
import flask_monitoringdashboard as dashboard
@@ -221,7 +222,7 @@
221222
delete_trip,
222223
update_trip_type,
223224
attach_ticket_to_trips,
224-
delete_ticket_from_db
225+
delete_ticket_from_db,
225226
fetch_trips_paths
226227
)
227228
from src.paths import Path
@@ -591,9 +592,14 @@ def sort_key(item):
591592
sorted_country_codes = dict(sorted(country_codes.items(), key=sort_key))
592593
return sorted_country_codes
593594

595+
def db_lock_state():
596+
"""Check if database sync is currently in progress"""
597+
lock_file = osPath("db_sync.lock")
598+
return lock_file.exists()
594599

595-
app.jinja_env.globals.update(get_country_codes_from_files=get_country_codes_from_files)
596600

601+
app.jinja_env.globals.update(get_country_codes_from_files=get_country_codes_from_files)
602+
app.jinja_env.globals.update(db_lock_state=db_lock_state)
597603

598604
@app.route("/api/localtime", methods=["GET"])
599605
def get_local_time():
@@ -2514,22 +2520,25 @@ def update_user_count():
25142520
User.last_login >= twenty_four_hours_ago
25152521
).count()
25162522
today = datetime.utcnow().date()
2517-
with managed_cursor(mainConn) as cursor:
2518-
cursor.execute("SELECT number FROM daily_active_users WHERE date = ?", (today,))
2519-
result = cursor.fetchone()
2520-
if result:
2521-
current_count = result["number"]
2522-
if active_users_count > current_count:
2523+
try:
2524+
with managed_cursor(mainConn) as cursor:
2525+
cursor.execute("SELECT number FROM daily_active_users WHERE date = ?", (today,))
2526+
result = cursor.fetchone()
2527+
if result:
2528+
current_count = result["number"]
2529+
if active_users_count > current_count:
2530+
cursor.execute(
2531+
"UPDATE daily_active_users SET number = ? WHERE date = ?",
2532+
(active_users_count, today),
2533+
)
2534+
else:
25232535
cursor.execute(
2524-
"UPDATE daily_active_users SET number = ? WHERE date = ?",
2525-
(active_users_count, today),
2536+
"INSERT INTO daily_active_users (date, number) VALUES (?, ?)",
2537+
(today, active_users_count),
25262538
)
2527-
else:
2528-
cursor.execute(
2529-
"INSERT INTO daily_active_users (date, number) VALUES (?, ?)",
2530-
(today, active_users_count),
2531-
)
2532-
mainConn.commit()
2539+
mainConn.commit()
2540+
except:
2541+
pass
25332542

25342543

25352544
@app.route("/", methods=["GET", "POST"])

lang/cs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Vyzkoušejte nový router (zobrazuje elektrifikaci)",
622622
"news": "Zprávy Trainlog",
623623
"CO2": "CO₂e",
624-
"donate": "Kup mi kávu"
624+
"donate": "Kup mi kávu",
625+
"data_migration_message": "Probíhá migrace databáze. Zápisové operace jsou dočasně zakázány."
625626
}

lang/da.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Prøv ny router (viser elektrificering)",
622622
"news": "Trainlog Nyheder",
623623
"CO2": "CO₂e",
624-
"donate": "Køb mig en kaffe"
624+
"donate": "Køb mig en kaffe",
625+
"data_migration_message": "En databaseoverførsel er i gang. Skriveoperationer er midlertidigt deaktiveret."
625626
}

lang/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Neuen Router ausprobieren (zeigt Elektrifizierung)",
622622
"news": "Trainlog-Nachrichten",
623623
"CO2": "CO₂e",
624-
"donate": "Kauf mir einen Kaffee"
624+
"donate": "Kauf mir einen Kaffee",
625+
"data_migration_message": "Eine Datenbankmigration ist im Gange. Schreibvorgänge sind vorübergehend deaktiviert."
625626
}

lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Try new router (shows electrification)",
622622
"news": "Trainlog News",
623623
"CO2": "CO₂e",
624-
"donate": "Buy me a coffee"
624+
"donate": "Buy me a coffee",
625+
"data_migration_message": "A database migration is in progress. Write operations are temporarily disabled."
625626
}

lang/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Prueba el nuevo router (muestra electrificación)",
622622
"news": "Noticias de Trainlog",
623623
"CO2": "CO₂e",
624-
"donate": "Cómprame un café"
624+
"donate": "Cómprame un café",
625+
"data_migration_message": "Una migración de base de datos está en curso. Las operaciones de escritura están temporalmente deshabilitadas."
625626
}

lang/et.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Proovi uut ruuterit (kuvab elektrifitseerimist)",
622622
"news": "Trainlog Uudised",
623623
"CO2": "CO₂e",
624-
"donate": "Osta mulle kohv"
624+
"donate": "Osta mulle kohv",
625+
"data_migration_message": "Andmebaasi migratsioon on pooleli. Kirjutustoimingud on ajutiselt keelatud."
625626
}

lang/fi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Kokeile uutta reititintä (näyttää sähköistyksen)",
622622
"news": "Trainlog-uutiset",
623623
"CO2": "CO₂e",
624-
"donate": "Osta minulle kahvi"
624+
"donate": "Osta minulle kahvi",
625+
"data_migration_message": "Tietokannan siirto on käynnissä. Kirjoitustoiminnot ovat väliaikaisesti pois käytöstä."
625626
}

lang/fr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,5 +621,6 @@
621621
"useNewRouter": "Essayer le nouveau routeur (affiche l'électrification)",
622622
"news": "Actualités Trainlog",
623623
"CO2": "CO₂e",
624-
"donate": "M'offrir un café"
624+
"donate": "M'offrir un café",
625+
"data_migration_message": "Une migration de base de données est en cours. Les opérations d'écriture sont temporairement désactivées."
625626
}

0 commit comments

Comments
 (0)