From bbcf7e021d83a490121c908dff249c07ef7f72fc Mon Sep 17 00:00:00 2001 From: macgregor Date: Fri, 26 Oct 2012 17:23:47 +0530 Subject: [PATCH] scripts to convert from GTFS to sqlite; inc zip utils --- android/scripts/convGTFStoCSV.sh | 61 +++ android/scripts/convGTFStoSQL.sh | 61 +++ android/scripts/csve/insertStopSeq.sh | 36 ++ android/scripts/csve/insertStops.sh | 39 ++ android/scripts/csve/insertTripBusFreq.sh | 27 ++ android/scripts/csve/insertTripRoutes.sh | 33 ++ android/scripts/csve/insertTripSchedules.sh | 35 ++ android/scripts/env.sh | 48 +++ android/scripts/generateSQLiteDB.sh | 38 ++ android/scripts/sqle/insertStopSeq.sh | 41 ++ android/scripts/sqle/insertStops.sh | 40 ++ android/scripts/sqle/insertTripBusFreq.sh | 26 ++ android/scripts/sqle/insertTripFreq.sh | 26 ++ android/scripts/sqle/insertTripRoutes.sh | 40 ++ android/scripts/sqle/insertTripSchedules.sh | 36 ++ zipgen/ZipGen/ZipGen.iml | 12 + zipgen/ZipGen/src/CZipCreate.java | 45 ++ zipgen/zipkit.ipr | 166 +++++++ zipgen/zipkit.iws | 455 ++++++++++++++++++++ zipgen/zipkit.properties | 2 + 20 files changed, 1267 insertions(+) create mode 100755 android/scripts/convGTFStoCSV.sh create mode 100755 android/scripts/convGTFStoSQL.sh create mode 100755 android/scripts/csve/insertStopSeq.sh create mode 100755 android/scripts/csve/insertStops.sh create mode 100755 android/scripts/csve/insertTripBusFreq.sh create mode 100755 android/scripts/csve/insertTripRoutes.sh create mode 100755 android/scripts/csve/insertTripSchedules.sh create mode 100755 android/scripts/env.sh create mode 100755 android/scripts/generateSQLiteDB.sh create mode 100755 android/scripts/sqle/insertStopSeq.sh create mode 100755 android/scripts/sqle/insertStops.sh create mode 100755 android/scripts/sqle/insertTripBusFreq.sh create mode 100755 android/scripts/sqle/insertTripFreq.sh create mode 100755 android/scripts/sqle/insertTripRoutes.sh create mode 100755 android/scripts/sqle/insertTripSchedules.sh create mode 100755 zipgen/ZipGen/ZipGen.iml create mode 100755 zipgen/ZipGen/src/CZipCreate.java create mode 100755 zipgen/zipkit.ipr create mode 100755 zipgen/zipkit.iws create mode 100755 zipgen/zipkit.properties diff --git a/android/scripts/convGTFStoCSV.sh b/android/scripts/convGTFStoCSV.sh new file mode 100755 index 0000000..0c0218d --- /dev/null +++ b/android/scripts/convGTFStoCSV.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# Date: 17th Jan 2012 +# +# + +source "env.sh" + +if [ ${#} -eq 1 ] ; then + M_FORCE_GTFS_REFRESH=${1} +else + M_FORCE_GTFS_REFRESH=0 +fi + +if [ ! -d "${GTFS_INPUT}" ] ; then + mkdir -p "${GTFS_INPUT}" +fi + +if [ ! -d "${DATA_OUT}" ] ; then + mkdir -p "${DATA_OUT}" +fi + +pushd "${GTFS_INPUT}" + +if [ ! -f gtfs.zip ] || [ ${M_FORCE_GTFS_REFRESH} -eq 1 ] ; then + rm -f gtfs.zip + wget -O gtfs.zip "${M_GTFS_FEED}" + unzip gtfs.zip + + dos2unix "${FILE_IN_STOPS}" + dos2unix "${FILE_IN_ROUTES}" + dos2unix "${FILE_IN_TRIPS}" + dos2unix "${FILE_IN_CALENDAR}" + dos2unix "${FILE_IN_STOP_TIMES}" +fi + +popd + +echo "---- -------- ----- ------ ----------- ------ -----" + +echo -n "Info: Generating Stop Name Geo Entries ... " +./csve/insertStops.sh "${FILE_IN_STOPS}" "${FILE_OUT_STOPS_NAMES}" "${FILE_OUT_STOPS_GEO}" +echo "done" + +echo -n "Info: Generating Trip Bus Freq Entries ... " +./csve/insertTripBusFreq.sh "${FILE_IN_FREQ}" "${FILE_OUT_FREQ}" +echo "done" + +echo -n "Info: Generating Trip Route Entries ... " +./csve/insertTripRoutes.sh "${FILE_IN_ROUTES}" "${FILE_OUT_ROUTES}" "${FILE_IN_TRIPS}" "${FILE_OUT_TRIPS}" +echo "done" + +echo -n "Info: Generating Schedule Entries ... " +./csve/insertTripSchedules.sh "${FILE_IN_CALENDAR}" "${FILE_OUT_CALENDAR}" +echo "done" + +echo -n "Info: Generating Stop Trip Sequence Entries ... " +./csve/insertStopSeq.sh "${FILE_IN_STOP_TIMES}" "${FILE_OUT_STOP_SEQ}" +echo "done" diff --git a/android/scripts/convGTFStoSQL.sh b/android/scripts/convGTFStoSQL.sh new file mode 100755 index 0000000..578cef8 --- /dev/null +++ b/android/scripts/convGTFStoSQL.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# Date: 17th Jan 2012 +# +# + +source "env.sh" + +if [ ${#} -eq 1 ] ; then + M_FORCE_GTFS_REFRESH=${1} +else + M_FORCE_GTFS_REFRESH=0 +fi + +if [ ! -d "${GTFS_INPUT}" ] ; then + mkdir -p "${GTFS_INPUT}" +fi + +if [ ! -d "${DATA_OUT}" ] ; then + mkdir -p "${DATA_OUT}" +fi + +pushd "${GTFS_INPUT}" + +if [ ! -f gtfs.zip ] || [ ${M_FORCE_GTFS_REFRESH} -eq 1 ] ; then + rm -f gtfs.zip + wget -O gtfs.zip "${M_GTFS_FEED}" + unzip gtfs.zip + + dos2unix "${FILE_IN_STOPS}" + dos2unix "${FILE_IN_ROUTES}" + dos2unix "${FILE_IN_TRIPS}" + dos2unix "${FILE_IN_CALENDAR}" + dos2unix "${FILE_IN_STOP_TIMES}" +fi + +popd + +echo -n "Info: Generating Stop Name Geo Entries ... " +./sqle/insertStops.sh "${FILE_IN_STOPS}" "${FILE_OUT_STOPS_NAMES}" "${FILE_OUT_STOPS_GEO}" +echo "done" + +echo -n "Info: Generating Trip Bus Freq Entries ... " +./sqle/insertTripBusFreq.sh "${FILE_IN_FREQ}" "${FILE_OUT_FREQ}" +echo "done" + +echo -n "Info: Generating Trip Route Entries ... " +./sqle/insertTripRoutes.sh "${FILE_IN_ROUTES}" "${FILE_OUT_ROUTES}" "${FILE_IN_TRIPS}" "${FILE_OUT_TRIPS}" +echo "done" + +echo -n "Info: Generating Schedule Entries ... " +./sqle/insertTripSchedules.sh "${FILE_IN_CALENDAR}" "${FILE_OUT_CALENDAR}" +echo "done" + +echo -n "Info: Generating Stop Trip Sequence Entries ... " +./sqle/insertStopSeq.sh "${FILE_IN_STOP_TIMES}" "${FILE_OUT_STOP_SEQ}" +echo "done" + +echo "---- -------- ----- ------ ----------- ------ -----" diff --git a/android/scripts/csve/insertStopSeq.sh b/android/scripts/csve/insertStopSeq.sh new file mode 100755 index 0000000..e3c3144 --- /dev/null +++ b/android/scripts/csve/insertStopSeq.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +#trip_id,arrival_time,departure_time,stop_id,stop_sequence -- FOR MUMBAI + +if [ ${#} -eq 2 ] ; then + FILE_IN_STOP_TIMES="${1}" + FILE_OUT_STOP_SEQ="${2}" + + cat "${FILE_IN_STOP_TIMES}" | grep -v "stop_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" -F ',' '{ + pickup_type = $7; drop_off_type = $8; + if( ( ( pickup_type == "" ) &&( drop_off_type == "" ) ) || ( ( pickup_type == 0 ) && ( drop_off_type == 0 ) ) ) { + trip_id=$1; arri_time=$2; dept_time=$3; stop_id=$4; stop_seq=$5; + + if( arri_time == "" ) + arri_time = "00:00:00"; + if( dept_time == "" ) + dept_time = "00:00:00"; + + stop_seq = stop_seq; + + split(dept_time, parts_dept_time, ":"); split(arri_time, parts_arri_time, ":"); + + if( parts_dept_time[1] >= 24 ) + { dept_time_next_day = "true"; dept_time = (parts_dept_time[1] - 24) ":" parts_dept_time[2] ":" parts_dept_time[3] } + else { dept_time_next_day = "false"; } + if( parts_arri_time[1] >= 24 ) + { arri_time_next_day = "true"; arri_time = (parts_arri_time[1] - 24) ":" parts_arri_time[2] ":" parts_arri_time[3] } + else { arri_time_next_day = "false"; } + + print trip_id sq stop_id sq stop_seq sq dept_time sq dept_time_next_day sq arri_time sq arri_time_next_day; + } + }' | grep -v "^$" >"${FILE_OUT_STOP_SEQ}" +fi \ No newline at end of file diff --git a/android/scripts/csve/insertStops.sh b/android/scripts/csve/insertStops.sh new file mode 100755 index 0000000..0c5c7de --- /dev/null +++ b/android/scripts/csve/insertStops.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# + +if [ ${#} -eq 3 ] ; then + FILE_IN_STOPS="${1}" + FILE_OUT_STOPS_NAMES="${2}" + FILE_OUT_STOPS_GEO="${3}" + + cat "${FILE_IN_STOPS}" | grep -v "stop_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" -F ',' '{ + stop_id=$1; stop_name=$2; stop_dec=$5; + + if(length(stop_id)>0) + { + sub( sq, sq""sq, stop_name ); + if( split( stop_dec, stop_dec_parts, ":" ) == 4 ) + { + stop_name_marathi = stop_dec_parts[2]; + sub( " Road", "", stop_name_marathi ); + stop_road = stop_dec_parts[3]; + sub( " Area", "", stop_road ); + stop_area = stop_dec_parts[4]; + # _stopID, _stopName, _stopNameMarathi, _stopRoad, _stopArea + print stop_id sq stop_name sq stop_name_marathi sq stop_road sq stop_areas; + } + } + }' | grep -v "^$" >"${FILE_OUT_STOPS_NAMES}" + + cat "${FILE_IN_STOPS}" | grep -v "stop_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" -F ',' '{ + stop_id=$1; stop_lat=$3; stop_long=$4; + if( (length(stop_id)>0) && (length(stop_lat)>0) && (length(stop_long)>0) ) + { + print stop_id sq stop_lat sq stop_long; + } + }' | grep -v "^$" >"${FILE_OUT_STOPS_GEO}" +fi \ No newline at end of file diff --git a/android/scripts/csve/insertTripBusFreq.sh b/android/scripts/csve/insertTripBusFreq.sh new file mode 100755 index 0000000..e28f189 --- /dev/null +++ b/android/scripts/csve/insertTripBusFreq.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# routes = route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color +# route_id,route_short_name,route_long_name,route_type --for MUMBAI routes +# route_id,service_id,trip_id --for MUMBAI trips + +if [ ${#} -eq 2 ] ; then + + FILE_IN_FREQ="${1}" + FILE_OUT_FREQ="${2}" + + # FPAT regex parse CSV and then strip not needed quotes from field data + cat "${FILE_IN_FREQ}" | grep -v "trip_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" 'BEGIN { FPAT = "([^,]*)|(\"[^\"]+\")" } { + trip_id = $1; start_time = $2; end_time = $3; headways = $4; + + if( length(alltrips[trip_id]) > 0 ) + alltrips[trip_id] = ((alltrips[trip_id] + headways) / 2); # hack: ouch average out the headways! + else + alltrips[trip_id] = headways; + } END { + for( tid in alltrips) + print tid sq int(alltrips[tid]); + }' | grep -v "^$" | tr -d '"' >"${FILE_OUT_FREQ}" +fi \ No newline at end of file diff --git a/android/scripts/csve/insertTripRoutes.sh b/android/scripts/csve/insertTripRoutes.sh new file mode 100755 index 0000000..823139e --- /dev/null +++ b/android/scripts/csve/insertTripRoutes.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# routes = route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color +# route_id,route_short_name,route_long_name,route_type --for MUMBAI routes +# route_id,service_id,trip_id --for MUMBAI trips + +if [ ${#} -eq 4 ] ; then + FILE_IN_ROUTES="${1}" + FILE_OUT_ROUTES="${2}" + + FILE_IN_TRIPS="${3}" + FILE_OUT_TRIPS="${4}" + + cat "${FILE_IN_ROUTES}" | grep -v "route_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" -F ',' '{ + route_id = $1; agency_id = $2; route_short_name = $3; route_long_name = $4; route_type = $5; + + if(route_type==0) { route_type="Tram"; } else if(route_type==1) { route_type="Subway"; } else if(route_type==2) { route_type="Rail"; } else if(route_type==3) { route_type="Bus"; } else if(route_type==4) { route_type="Ferry"; } else if(route_type==5) { route_type="Cable car"; } else if(route_type==6) { route_type="Gondola"; } else if(route_type==7) { route_type="Funicular"; } else { route_type=""; } + + if(route_type=="") { route_type="Bus"; } + + print route_id sq agency_id sq route_short_name sq route_long_name sq route_type; + }' >"${FILE_OUT_ROUTES}" + + # FPAT regex used to parse CSV data where a comma is in the field; further strip quotes from result as that is not part of the field data. + cat "${FILE_IN_TRIPS}" | grep -v "route_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" 'BEGIN { FPAT = "([^,]*)|(\"[^\"]+\")" } { + route_id = $1; service_id = $2; trip_id = $3; trip_sign = $4; + + print trip_id sq route_id sq service_id sq trip_sign; + }' | grep -v "^$" | tr -d '"' >"${FILE_OUT_TRIPS}" +fi \ No newline at end of file diff --git a/android/scripts/csve/insertTripSchedules.sh b/android/scripts/csve/insertTripSchedules.sh new file mode 100755 index 0000000..ced0cdd --- /dev/null +++ b/android/scripts/csve/insertTripSchedules.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +#service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date -- FOR MUMBAI + +if [ ${#} -eq 2 ] ; then + FILE_IN_CALENDAR="${1}" + FILE_OUT_CALENDAR="${2}" + + cat "${FILE_IN_CALENDAR}" | grep -v "^service_id" | gawk -v sq="${SQLITE_DB_IMPORT_SEP}" -F ',' '{ + if(NF==10) + { + service_id=$1; service_date_start=$9; service_date_end=$10; service_day=""; + + for( ix=2; ix<=8; ix++ ) + { + if( (ix==2) && ($ix=="1") ) { service_day="Mon"; } + else if( (ix==3) && ($ix=="1") ) { service_day="Tue"; } + else if( (ix==4) && ($ix=="1") ) { service_day="Wed"; } + else if( (ix==5) && ($ix=="1") ) { service_day="Thu"; } + else if( (ix==6) && ($ix=="1") ) { service_day="Fri"; } + else if( (ix==7) && ($ix=="1") ) { service_day="Sat"; } + else if( (ix==8) && ($ix=="1") ) { service_day="Sun"; } + else { service_day=""; } + + if(service_day != "") + { + print service_id sq service_day sq service_date_start sq service_date_end; + } + } + } + }' | grep -v "^$" >"${FILE_OUT_CALENDAR}" +fi \ No newline at end of file diff --git a/android/scripts/env.sh b/android/scripts/env.sh new file mode 100755 index 0000000..1d90f8c --- /dev/null +++ b/android/scripts/env.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# + +export M_PROCESS_FOR="Mumbai" +export M_GTFS_FEED='http://gtfs.chalobest.in/gtfs_0.9.5.zip' +export SQLITE_DB_IMPORT_SEP="~" + +if [ $(uname -a | grep -i -c cygwin) -ge 1 ] ; then + export M_BASE="/cygdrive/d/dev/new_dev/BESTMobile/" +else + export M_BASE="/var/working/transportation" +fi + +M_DB_ID="gt${M_PROCESS_FOR}" + +GTFS_INPUT="${M_BASE}/GTFS/${M_PROCESS_FOR}" +DATA_OUT="${M_BASE}/data/${M_PROCESS_FOR}" + +TMP_WORK_FILE="${DATA_OUT}/__tmp" + +DATA_SQLITE_DB_CORE="${DATA_OUT}/android-db.sqlite" +DATA_SQLITE_DB_CREATE="${M_BASE}/BESTMobile/android/db/create-sqlite-android.sql" + +FILE_DB_CREATE="${M_BASE}/web/db/create-template.txt" + +FILE_IN_FREQ="${GTFS_INPUT}/frequencies.txt" +FILE_OUT_FREQ="${DATA_OUT}/frequencies.txt" + +FILE_IN_STOPS="${GTFS_INPUT}/stops.txt" +FILE_IN_STOP_TIMES="${GTFS_INPUT}/stop_times.txt" +FILE_OUT_STOPS_NAMES="${DATA_OUT}/stop_names.txt" +FILE_OUT_STOPS_GEO="${DATA_OUT}/stop_geo.txt" + +FILE_IN_STOP_TIMES="${GTFS_INPUT}/stop_times.txt" +FILE_OUT_STOP_SEQ="${DATA_OUT}/stop_seq.txt" + +FILE_IN_ROUTES="${GTFS_INPUT}/routes.txt" +FILE_OUT_ROUTES="${DATA_OUT}/routes.txt" + +FILE_IN_TRIPS="${GTFS_INPUT}/trips.txt" +FILE_OUT_TRIPS="${DATA_OUT}/trips.txt" + +FILE_IN_CALENDAR="${GTFS_INPUT}/calendar.txt" +FILE_OUT_CALENDAR="${DATA_OUT}/trip_schedules.txt" diff --git a/android/scripts/generateSQLiteDB.sh b/android/scripts/generateSQLiteDB.sh new file mode 100755 index 0000000..ea2b140 --- /dev/null +++ b/android/scripts/generateSQLiteDB.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# Date: 25th Oct 2012 +# +# + +source "env.sh" + +if [ -f ${DATA_SQLITE_DB_CORE} ] ; then + rm -vf ${DATA_SQLITE_DB_CORE} +fi + +echo -n "Info: Generating sqlite data base ... " + +# Create the DB +cat ${DATA_SQLITE_DB_CREATE} | sqlite3 ${DATA_SQLITE_DB_CORE} + +# Import the data +echo .separator \"${SQLITE_DB_IMPORT_SEP}\" >${TMP_WORK_FILE} +echo .import \"${FILE_OUT_STOPS_NAMES}\" stop_names >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_STOPS_GEO}\" stop_geo >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_FREQ}\" bus_max_freq >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_ROUTES}\" routes >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_TRIPS}\" trips >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_CALENDAR}\" schedule_rules >>${TMP_WORK_FILE} +echo .import \"${FILE_OUT_STOP_SEQ}\" stops_on_trip >>${TMP_WORK_FILE} + +cat ${TMP_WORK_FILE} | sqlite3 ${DATA_SQLITE_DB_CORE} + +rm -f ${TMP_WORK_FILE} + +echo "done." + + + + diff --git a/android/scripts/sqle/insertStopSeq.sh b/android/scripts/sqle/insertStopSeq.sh new file mode 100755 index 0000000..f822e3b --- /dev/null +++ b/android/scripts/sqle/insertStopSeq.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +#trip_id,arrival_time,departure_time,stop_id,stop_sequence -- FOR MUMBAI + +if [ ${#} -eq 2 ] ; then + FILE_IN_STOP_TIMES="${1}" + FILE_OUT_STOP_SEQ="${2}" + + #print "insert into stops_on_trip (_tripID, _stopID, _stopSeq, _stopDept, _stopDeptOnNextDay, _stopArri, _stopArriOnNextDay) values (" sq trip_id sq "," sq stop_id sq "," stop_seq "," sq dept_time sq "," dept_time_next_day "," sq arri_time sq "," arri_time_next_day ");" + + #print sq trip_id sq "," sq stop_id sq "," stop_seq "," sq dept_time sq "," dept_time_next_day "," sq arri_time sq "," arri_time_next_day; + + echo "delete from stops_on_trip;" >"${FILE_OUT_STOP_SEQ}" + cat "${FILE_IN_STOP_TIMES}" | grep -v "stop_id" | gawk -v sq="'" -F ',' '{ + pickup_type = $7; drop_off_type = $8; + if( ( ( pickup_type == "" ) &&( drop_off_type == "" ) ) || ( ( pickup_type == 0 ) && ( drop_off_type == 0 ) ) ) { + trip_id=$1; arri_time=$2; dept_time=$3; stop_id=$4; stop_seq=$5; + + if( arri_time == "" ) + arri_time = "00:00:00"; + if( dept_time == "" ) + dept_time = "00:00:00"; + + stop_seq = stop_seq; + + split(dept_time, parts_dept_time, ":"); split(arri_time, parts_arri_time, ":"); + + if( parts_dept_time[1] >= 24 ) + { dept_time_next_day = "true"; dept_time = (parts_dept_time[1] - 24) ":" parts_dept_time[2] ":" parts_dept_time[3] } + else { dept_time_next_day = "false"; } + if( parts_arri_time[1] >= 24 ) + { arri_time_next_day = "true"; arri_time = (parts_arri_time[1] - 24) ":" parts_arri_time[2] ":" parts_arri_time[3] } + else { arri_time_next_day = "false"; } + + print "insert into stops_on_trip (_tripID, _stopID, _stopSeq, _stopDept, _stopDeptOnNextDay, _stopArri, _stopArriOnNextDay) values (" sq trip_id sq "," sq stop_id sq "," stop_seq "," sq dept_time sq "," dept_time_next_day "," sq arri_time sq "," arri_time_next_day ");" + } + }' >>"${FILE_OUT_STOP_SEQ}" +fi \ No newline at end of file diff --git a/android/scripts/sqle/insertStops.sh b/android/scripts/sqle/insertStops.sh new file mode 100755 index 0000000..89afcde --- /dev/null +++ b/android/scripts/sqle/insertStops.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# + +if [ ${#} -eq 3 ] ; then + FILE_IN_STOPS="${1}" + FILE_OUT_STOPS_NAMES="${2}" + FILE_OUT_STOPS_GEO="${3}" + + echo "delete from stop_names;" >"${FILE_OUT_STOPS_NAMES}" + cat "${FILE_IN_STOPS}" | grep -v "stop_id" | gawk -v sq="'" -F ',' '{ + stop_id=$1; stop_name=$2; stop_dec=$5; + + if(length(stop_id)>0) + { + sub( sq, sq""sq, stop_name ); + if( split( stop_dec, stop_dec_parts, ":" ) == 4 ) + { + stop_name_marathi = stop_dec_parts[2]; + sub( " Road", "", stop_name_marathi ); + stop_road = stop_dec_parts[3]; + sub( " Area", "", stop_road ); + stop_area = stop_dec_parts[4]; + print "insert into stop_names (_stopID, _stopName, _stopNameMarathi, _stopRoad, _stopArea) values (" sq stop_id sq "," sq stop_name sq "," sq stop_name_marathi sq "," sq stop_road sq "," sq stop_area sq");" + } + } + }' | grep -v "^$" >>"${FILE_OUT_STOPS_NAMES}" + + echo "delete from stop_geo;" >"${FILE_OUT_STOPS_GEO}" + cat "${FILE_IN_STOPS}" | grep -v "stop_id" | gawk -v sq="'" -F ',' '{ + stop_id=$1; stop_lat=$3; stop_long=$4; + if( (length(stop_id)>0) && (length(stop_lat)>0) && (length(stop_long)>0) ) + { + print "insert into stop_geo (_stopID, _stopLat, _stopLon) values (" sq stop_id sq "," stop_lat "," stop_long ");" + } + }' | grep -v "^$" >>"${FILE_OUT_STOPS_GEO}" +fi \ No newline at end of file diff --git a/android/scripts/sqle/insertTripBusFreq.sh b/android/scripts/sqle/insertTripBusFreq.sh new file mode 100755 index 0000000..aaffc73 --- /dev/null +++ b/android/scripts/sqle/insertTripBusFreq.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# routes = route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color +# route_id,route_short_name,route_long_name,route_type --for MUMBAI routes +# route_id,service_id,trip_id --for MUMBAI trips + +if [ ${#} -eq 2 ] ; then + + FILE_IN_FREQ="${1}" + FILE_OUT_FREQ="${2}" + + echo "delete from bus_max_freq;" >"${FILE_OUT_FREQ}" + cat "${FILE_IN_FREQ}" | grep -v "trip_id" | gawk -v sq="'" -F ',' '{ + trip_id = $1; start_time = $2; end_time = $3; headways = $4; + if( length(alltrips[trip_id]) > 0 ) + alltrips[trip_id] = ((alltrips[trip_id] + headways) / 2); # hack: ouch average out the headways! + else + alltrips[trip_id] = headways; + } END { + for( tid in alltrips) + print "insert into bus_max_freq (_tripID, _freq) values (" sq tid sq "," int(alltrips[tid]) ");" + }' >>"${FILE_OUT_FREQ}" +fi \ No newline at end of file diff --git a/android/scripts/sqle/insertTripFreq.sh b/android/scripts/sqle/insertTripFreq.sh new file mode 100755 index 0000000..93e5fda --- /dev/null +++ b/android/scripts/sqle/insertTripFreq.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# routes = route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color +# route_id,route_short_name,route_long_name,route_type --for MUMBAI routes +# route_id,service_id,trip_id --for MUMBAI trips + +if [ ${#} -eq 2 ] ; then + FILE_IN_FREQ="${1}" + FILE_OUT_FREQ="${2}" + + echo "delete from trips_freq;" >"${FILE_OUT_FREQ}" + cat "${FILE_IN_FREQ}" | grep -v "trip_id" | gawk -v sq="'" -F ',' '{ + trip_id = $1; start_time = $2; end_time = $3; headways = $4; + + split(end_time, parts_end_time, ":"); + + if( parts_end_time[1] >= 24 ) + { end_time_next_day = "true"; end_time = (parts_end_time[1] - 24) ":" parts_end_time[2] ":" parts_end_time[3]; } + else { end_time_next_day = "false"; } + + print "insert into trips_freq (_tripID, _start, _end, _end_next_day, _headways) values (" sq trip_id sq "," sq start_time sq "," sq end_time sq "," end_time_next_day "," sq headways sq ");" + }' >>"${FILE_OUT_FREQ}" +fi \ No newline at end of file diff --git a/android/scripts/sqle/insertTripRoutes.sh b/android/scripts/sqle/insertTripRoutes.sh new file mode 100755 index 0000000..92d6161 --- /dev/null +++ b/android/scripts/sqle/insertTripRoutes.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +# routes = route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color +# route_id,route_short_name,route_long_name,route_type --for MUMBAI routes +# route_id,service_id,trip_id --for MUMBAI trips + +if [ ${#} -eq 4 ] ; then + FILE_IN_ROUTES="${1}" + FILE_OUT_ROUTES="${2}" + + FILE_IN_TRIPS="${3}" + FILE_OUT_TRIPS="${4}" + + echo "delete from routes;" >"${FILE_OUT_ROUTES}" + cat "${FILE_IN_ROUTES}" | grep -v "route_id" | gawk -v sq="'" -F ',' '{ + route_id = $1; agency_id = $2; route_short_name = $3; route_long_name = $4; route_type = $5; + + sub( sq, sq""sq, route_short_name ); + sub( sq, sq""sq, route_long_name ); + sub( sq, sq""sq, route_type ); + + if(route_type==0) { route_type="Tram"; } else if(route_type==1) { route_type="Subway"; } else if(route_type==2) { route_type="Rail"; } else if(route_type==3) { route_type="Bus"; } else if(route_type==4) { route_type="Ferry"; } else if(route_type==5) { route_type="Cable car"; } else if(route_type==6) { route_type="Gondola"; } else if(route_type==7) { route_type="Funicular"; } else { route_type=""; } + + if(route_type=="") { route_type="Bus"; } + + print "insert into routes (_routeID, _agencyID, _routeName, _routeLongName, _routeType) values (" sq route_id sq "," sq agency_id sq "," sq route_short_name sq "," sq route_long_name sq "," sq route_type sq ");" + }' >>"${FILE_OUT_ROUTES}" + + echo "delete from trips;" >"${FILE_OUT_TRIPS}" + cat "${FILE_IN_TRIPS}" | grep -v "route_id" | gawk -v sq="'" -F ',' '{ + route_id = $1; service_id = $2; trip_id = $3; trip_sign = $4; + + sub( sq, sq""sq, trip_sign ); + + print "insert into trips (_tripID, _routeID, _serviceID, _tripHeadSign) values (" sq trip_id sq "," sq route_id sq "," sq service_id sq "," sq trip_sign sq ");" + }' >>"${FILE_OUT_TRIPS}" +fi \ No newline at end of file diff --git a/android/scripts/sqle/insertTripSchedules.sh b/android/scripts/sqle/insertTripSchedules.sh new file mode 100755 index 0000000..c37b9e1 --- /dev/null +++ b/android/scripts/sqle/insertTripSchedules.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Author: Macgregor +# Liscense: GPLv3 +# +#service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date -- FOR MUMBAI + +if [ ${#} -eq 2 ] ; then + FILE_IN_CALENDAR="${1}" + FILE_OUT_CALENDAR="${2}" + + echo "delete from schedule_rules;" >"${FILE_OUT_CALENDAR}" + cat "${FILE_IN_CALENDAR}" | grep -v "^service_id" | gawk -v sq="'" -F ',' '{ + if(NF==10) + { + service_id=$1; service_date_start=$9; service_date_end=$10; service_day=""; + + for( ix=2; ix<=8; ix++ ) + { + if( (ix==2) && ($ix=="1") ) { service_day="Mon"; } + else if( (ix==3) && ($ix=="1") ) { service_day="Tue"; } + else if( (ix==4) && ($ix=="1") ) { service_day="Wed"; } + else if( (ix==5) && ($ix=="1") ) { service_day="Thu"; } + else if( (ix==6) && ($ix=="1") ) { service_day="Fri"; } + else if( (ix==7) && ($ix=="1") ) { service_day="Sat"; } + else if( (ix==8) && ($ix=="1") ) { service_day="Sun"; } + else { service_day=""; } + + if(service_day != "") + { + print "insert into schedule_rules (_serviceID, _serviceDay, _startPeriodDate, _endPeriodDate) values (" sq service_id sq "," sq service_day sq "," sq service_date_start sq "," sq service_date_end sq ");" + } + } + } + }' >>"${FILE_OUT_CALENDAR}" +fi \ No newline at end of file diff --git a/zipgen/ZipGen/ZipGen.iml b/zipgen/ZipGen/ZipGen.iml new file mode 100755 index 0000000..bcd2974 --- /dev/null +++ b/zipgen/ZipGen/ZipGen.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/zipgen/ZipGen/src/CZipCreate.java b/zipgen/ZipGen/src/CZipCreate.java new file mode 100755 index 0000000..e1fc6b2 --- /dev/null +++ b/zipgen/ZipGen/src/CZipCreate.java @@ -0,0 +1,45 @@ +/** + * Author: Macgregor + * License: GPLv3 + */ + +import java.io.*; +import java.util.zip.*; + +public class CZipCreate +{ + public static void writeGZ(String inFileName) + { + try + { + File file = new File(inFileName); + FileOutputStream fos = new FileOutputStream(file + ".gz"); + GZIPOutputStream gzos = new GZIPOutputStream(fos); + FileInputStream fin = new FileInputStream(file); + BufferedInputStream in = new BufferedInputStream(fin); + + System.out.println("Creating FAT filesystem (MS-DOS, OS/2, NT) GZip: " + inFileName + " to "+ file + ".gz"); + + byte[] buffer = new byte[1024]; + int i = -1; + + while ((i = in.read(buffer)) >= 0) + gzos.write(buffer,0,i); + + in.close(); + gzos.close(); + } + catch(IOException e) + { + System.out.println("Error: " + e); + e.printStackTrace(); + } + } + + public static void main(String args[]){ + if(args.length == 1) + writeGZ(args[0]); + else + System.out.println("Raw Input Missing."); + } +} diff --git a/zipgen/zipkit.ipr b/zipgen/zipkit.ipr new file mode 100755 index 0000000..8b240fb --- /dev/null +++ b/zipgen/zipkit.ipr @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/zipgen/zipkit.iws b/zipgen/zipkit.iws new file mode 100755 index 0000000..6d777d0 --- /dev/null +++ b/zipgen/zipkit.iws @@ -0,0 +1,455 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + 1351248138053 + 1351248138053 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.6 (1) + + + + + + + + + diff --git a/zipgen/zipkit.properties b/zipgen/zipkit.properties new file mode 100755 index 0000000..25342d2 --- /dev/null +++ b/zipgen/zipkit.properties @@ -0,0 +1,2 @@ +path.variable.maven_repository=C\:\\Users\\Jamie\\.m2\\repository +jdk.home.1.6_(1)=C\:/Program Files/Java/jdk1.6.0_20 \ No newline at end of file