Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ start-db:
start-local: start-db
env $$(cat .env | xargs) POSTGRES_HOST=localhost FLASK_APP=app gunicorn --timeout 1000 --bind 0.0.0.0:5000 app:app --reload --access-logfile - --access-logformat '%(h)s %(r)s %(s)s'

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

# stop all containers
stop:
docker compose down
Expand Down
46 changes: 28 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from io import BytesIO, StringIO
from shapely.geometry import shape, mapping
from shapely.ops import unary_union
from pathlib import Path as osPath

import distinctipy
import flask_monitoringdashboard as dashboard
Expand Down Expand Up @@ -221,7 +222,8 @@
delete_trip,
update_trip_type,
attach_ticket_to_trips,
delete_ticket_from_db
delete_ticket_from_db,
fetch_trips_paths
)
from src.paths import Path
from src.carbon import *
Expand Down Expand Up @@ -590,9 +592,14 @@ def sort_key(item):
sorted_country_codes = dict(sorted(country_codes.items(), key=sort_key))
return sorted_country_codes

def db_lock_state():
"""Check if database sync is currently in progress"""
lock_file = osPath("db_sync.lock")
return lock_file.exists()

app.jinja_env.globals.update(get_country_codes_from_files=get_country_codes_from_files)

app.jinja_env.globals.update(get_country_codes_from_files=get_country_codes_from_files)
app.jinja_env.globals.update(db_lock_state=db_lock_state)

@app.route("/api/localtime", methods=["GET"])
def get_local_time():
Expand Down Expand Up @@ -2513,22 +2520,25 @@ def update_user_count():
User.last_login >= twenty_four_hours_ago
).count()
today = datetime.utcnow().date()
with managed_cursor(mainConn) as cursor:
cursor.execute("SELECT number FROM daily_active_users WHERE date = ?", (today,))
result = cursor.fetchone()
if result:
current_count = result["number"]
if active_users_count > current_count:
try:
with managed_cursor(mainConn) as cursor:
cursor.execute("SELECT number FROM daily_active_users WHERE date = ?", (today,))
result = cursor.fetchone()
if result:
current_count = result["number"]
if active_users_count > current_count:
cursor.execute(
"UPDATE daily_active_users SET number = ? WHERE date = ?",
(active_users_count, today),
)
else:
cursor.execute(
"UPDATE daily_active_users SET number = ? WHERE date = ?",
(active_users_count, today),
"INSERT INTO daily_active_users (date, number) VALUES (?, ?)",
(today, active_users_count),
)
else:
cursor.execute(
"INSERT INTO daily_active_users (date, number) VALUES (?, ?)",
(today, active_users_count),
)
mainConn.commit()
mainConn.commit()
except:
pass


@app.route("/", methods=["GET", "POST"])
Expand Down Expand Up @@ -5290,14 +5300,14 @@ def fetchTripsPaths(username, lastLocal, public):
@app.route("/public/<username>/getTripsPaths/<lastLocal>", methods=["GET", "POST"])
@public_required # Public access check
def public_getTripsPaths(username, lastLocal):
result = fetchTripsPaths(username, lastLocal, public=1)
result = fetch_trips_paths(username, lastLocal, public=1)
return jsonify(result)


@app.route("/<username>/getTripsPaths/<lastLocal>", methods=["GET", "POST"])
@login_required # Login access check
def getTripsPaths(username, lastLocal):
result = fetchTripsPaths(username, lastLocal, public=0)
result = fetch_trips_paths(username, lastLocal, public=0)
return jsonify(result)


Expand Down
3 changes: 2 additions & 1 deletion lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Vyzkoušejte nový router (zobrazuje elektrifikaci)",
"news": "Zprávy Trainlog",
"CO2": "CO₂e",
"donate": "Kup mi kávu"
"donate": "Kup mi kávu",
"data_migration_message": "Probíhá migrace databáze. Zápisové operace jsou dočasně zakázány."
}
3 changes: 2 additions & 1 deletion lang/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prøv ny router (viser elektrificering)",
"news": "Trainlog Nyheder",
"CO2": "CO₂e",
"donate": "Køb mig en kaffe"
"donate": "Køb mig en kaffe",
"data_migration_message": "En databaseoverførsel er i gang. Skriveoperationer er midlertidigt deaktiveret."
}
3 changes: 2 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Neuen Router ausprobieren (zeigt Elektrifizierung)",
"news": "Trainlog-Nachrichten",
"CO2": "CO₂e",
"donate": "Kauf mir einen Kaffee"
"donate": "Kauf mir einen Kaffee",
"data_migration_message": "Eine Datenbankmigration ist im Gange. Schreibvorgänge sind vorübergehend deaktiviert."
}
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Try new router (shows electrification)",
"news": "Trainlog News",
"CO2": "CO₂e",
"donate": "Buy me a coffee"
"donate": "Buy me a coffee",
"data_migration_message": "A database migration is in progress. Write operations are temporarily disabled."
}
3 changes: 2 additions & 1 deletion lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prueba el nuevo router (muestra electrificación)",
"news": "Noticias de Trainlog",
"CO2": "CO₂e",
"donate": "Cómprame un café"
"donate": "Cómprame un café",
"data_migration_message": "Una migración de base de datos está en curso. Las operaciones de escritura están temporalmente deshabilitadas."
}
3 changes: 2 additions & 1 deletion lang/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Proovi uut ruuterit (kuvab elektrifitseerimist)",
"news": "Trainlog Uudised",
"CO2": "CO₂e",
"donate": "Osta mulle kohv"
"donate": "Osta mulle kohv",
"data_migration_message": "Andmebaasi migratsioon on pooleli. Kirjutustoimingud on ajutiselt keelatud."
}
3 changes: 2 additions & 1 deletion lang/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Kokeile uutta reititintä (näyttää sähköistyksen)",
"news": "Trainlog-uutiset",
"CO2": "CO₂e",
"donate": "Osta minulle kahvi"
"donate": "Osta minulle kahvi",
"data_migration_message": "Tietokannan siirto on käynnissä. Kirjoitustoiminnot ovat väliaikaisesti pois käytöstä."
}
3 changes: 2 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Essayer le nouveau routeur (affiche l'électrification)",
"news": "Actualités Trainlog",
"CO2": "CO₂e",
"donate": "M'offrir un café"
"donate": "M'offrir un café",
"data_migration_message": "Une migration de base de données est en cours. Les opérations d'écriture sont temporairement désactivées."
}
3 changes: 2 additions & 1 deletion lang/gsw.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Probieret nejer Router (zeigt Elektrifizierung)",
"news": "Trainlog-Nachrichte",
"CO2": "CO₂e",
"donate": "Chauf mier es Kaffee"
"donate": "Chauf mier es Kaffee",
"data_migration_message": "E Datenbank-Migration isch im Gang. Schreiboperatione sind vorüübergehend deaktiviert."
}
3 changes: 2 additions & 1 deletion lang/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Isprobajte novi router (prikazuje elektrifikaciju)",
"news": "Vijesti Trainlog",
"CO2": "CO₂e",
"donate": "Kupi mi kavu"
"donate": "Kupi mi kavu",
"data_migration_message": "Migracija baze podataka je u tijeku. Operacije pisanja su privremeno onemogućene."
}
3 changes: 2 additions & 1 deletion lang/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Próbálja ki az új útválasztót (mutatja az elektromos hálózatot)",
"news": "Trainlog Hírek",
"CO2": "CO₂e",
"donate": "Vegyél nekem egy kávét"
"donate": "Vegyél nekem egy kávét",
"data_migration_message": "Egy adatbázis-migráció folyamatban van. Az írási műveletek ideiglenesen le vannak tiltva."
}
3 changes: 2 additions & 1 deletion lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prova il nuovo router (mostra l'elettrificazione)",
"news": "Notizie Trainlog",
"CO2": "CO₂e",
"donate": "Comprami un caffè"
"donate": "Comprami un caffè",
"data_migration_message": "Una migrazione del database è in corso. Le operazioni di scrittura sono temporaneamente disabilitate."
}
3 changes: 2 additions & 1 deletion lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "新しいルーターを試す(電化を表示)",
"news": "トレインログニュース",
"CO2": "CO₂e",
"donate": "コーヒーを買ってください"
"donate": "コーヒーを買ってください",
"data_migration_message": "データベースの移行が進行中です。書き込み操作は一時的に無効になっています。"
}
3 changes: 2 additions & 1 deletion lang/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "새 라우터를 시도하세요 (전력 공급을 표시)",
"news": "트레인로그 뉴스",
"CO2": "CO₂e",
"donate": "커피 한 잔 사줘"
"donate": "커피 한 잔 사줘",
"data_migration_message": "데이터베이스 마이그레이션이 진행 중입니다. 쓰기 작업이 일시적으로 비활성화되었습니다."
}
3 changes: 2 additions & 1 deletion lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Probeer nieuwe router (toont elektrificatie)",
"news": "Trainlog Nieuws",
"CO2": "CO₂e",
"donate": "Koop een koffie voor me"
"donate": "Koop een koffie voor me",
"data_migration_message": "Een databasemigratie is aan de gang. Schrijfhandelingen zijn tijdelijk uitgeschakeld."
}
3 changes: 2 additions & 1 deletion lang/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prøv ny ruter (viser elektrifisering)",
"news": "Trainlog Nyheter",
"CO2": "CO₂e",
"donate": "Kjøp meg en kaffe"
"donate": "Kjøp meg en kaffe",
"data_migration_message": "En databaseoverføring pågår. Skriveoperasjoner er midlertidig deaktivert."
}
3 changes: 2 additions & 1 deletion lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Wypróbuj nowy router (pokazuje elektryfikację)",
"news": "Wiadomości Trainlog",
"CO2": "CO₂e",
"donate": "Kup mi kawę"
"donate": "Kup mi kawę",
"data_migration_message": "Migracja bazy danych jest w toku. Operacje zapisu są tymczasowo wyłączone."
}
3 changes: 2 additions & 1 deletion lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Experimente o novo roteador (mostra eletrificação)",
"news": "Notícias do Trainlog",
"CO2": "CO₂e",
"donate": "Compre-me um café"
"donate": "Compre-me um café",
"data_migration_message": "Uma migração de banco de dados está em andamento. As operações de escrita estão temporariamente desativadas."
}
3 changes: 2 additions & 1 deletion lang/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Tente novo router (mostra eletrificação)",
"news": "Notícias do Trainlog",
"CO2": "CO₂e",
"donate": "Compra-me um café"
"donate": "Compra-me um café",
"data_migration_message": "Uma migração de base de dados está em progresso. As operações de escrita estão temporariamente desativadas."
}
3 changes: 2 additions & 1 deletion lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Попробуйте новый маршрутизатор (показывает электрификацию)",
"news": "Новости Trainlog",
"CO2": "CO₂e",
"donate": "Купи мне кофе"
"donate": "Купи мне кофе",
"data_migration_message": "Миграция базы данных в процессе. Операции записи временно отключены."
}
3 changes: 2 additions & 1 deletion lang/sv-FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prova ny router (visar elektrifiering)",
"news": "Trainlog Nyheter",
"CO2": "CO₂e",
"donate": "Köp mig en kaffe"
"donate": "Köp mig en kaffe",
"data_migration_message": "En databasöverföring pågår. Skrivoperationer är tillfälligt inaktiverade."
}
3 changes: 2 additions & 1 deletion lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Prova ny router (visar elektrifiering)",
"news": "Trainlog Nyheter",
"CO2": "CO₂e",
"donate": "Köp mig en kaffe"
"donate": "Köp mig en kaffe",
"data_migration_message": "En databasöverföring pågår. Skrivoperationer är tillfälligt inaktiverade."
}
3 changes: 2 additions & 1 deletion lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Yeni yönlendiriciyi deneyin (elektrifikasyonu gösterir)",
"news": "Trainlog Haberler",
"CO2": "CO₂e",
"donate": "Bana bir kahve al"
"donate": "Bana bir kahve al",
"data_migration_message": "Veritabanı geçişi devam ediyor. Yazma işlemleri geçici olarak devre dışı bırakıldı."
}
3 changes: 2 additions & 1 deletion lang/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "Спробуйте новий маршрутизатор (показує електрифікацію)",
"news": "Новини Trainlog",
"CO2": "CO₂e",
"donate": "Купи мені каву"
"donate": "Купи мені каву",
"data_migration_message": "Міграція бази даних триває. Операції запису тимчасово відключено."
}
3 changes: 2 additions & 1 deletion lang/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,6 @@
"useNewRouter": "尝试新路由器(显示电气化)",
"news": "Trainlog 新闻",
"CO2": "CO₂e",
"donate": "请给我买杯咖啡"
"donate": "请给我买杯咖啡",
"data_migration_message": "数据库迁移正在进行中。写入操作暂时被禁用。"
}
Loading