Skip to content

Instantly share code, notes, and snippets.

@saranrapjs
Created August 4, 2023 15:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saranrapjs/a723c81d277d65839bdb76da994fa11e to your computer and use it in GitHub Desktop.
Save saranrapjs/a723c81d277d65839bdb76da994fa11e to your computer and use it in GitHub Desktop.
Aggregating the $$$ you spend on OMNY by month

Aggregating the $$$ you spend on OMNY by month

The OMNY dashboard allows you to export Trip History as a CSV. This is a really basic script that aggregates how much you spend on OMNY by month, given the trip-history.csv file you get from OMNY.

Here's how you can run it from the unzipped OMNY download directory:

sqlite3 -init trips.sql trips.db .quit
.mode csv
DROP TABLE IF EXISTS trips;
DROP TABLE IF EXISTS trips_temp;
CREATE TABLE trips (
Ref1 TEXT,
Ref2 TEXT,
TripTime DATETIME,
Mode TEXT,
Location TEXT,
ProductType TEXT,
FareAmount NUMERIC
);
CREATE TABLE trips_temp (
Ref1 TEXT,
Ref2 TEXT,
TripTime DATETIME,
Mode TEXT,
Location TEXT,
ProductType TEXT,
FareAmount TEXT
);
.import trip-history.csv trips_temp
INSERT INTO trips (Ref1, Ref2, TripTime, Mode, Location, ProductType, FareAmount)
SELECT
Ref1,
Ref2,
TripTime,
Mode,
Location,
ProductType,
REPLACE(FareAmount, '$', '') AS FareAmount
FROM trips_temp;
DROP TABLE trips_temp;
SELECT
strftime('%Y-%m', TripTime) AS Month,
SUM(FareAmount) AS TotalFareAmount
FROM trips
GROUP BY Month
ORDER BY Month;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment