<commit_before>#!/usr/bin/env ruby

require 'csv'
require 'sqlite3'
require 'date'

SECONDS_IN_MINUTE = 60
SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60
SECONDS_IN_DAY = SECONDS_IN_HOUR * 24

DateTimeBits = Struct.new(:seconds_since_midnight,
                          :day_of_week,
                          :day_of_month,
                          :month,
                          :year)

def self.seconds_since_midnight(dt)
  (dt - dt.to_date) * SECONDS_IN_DAY
end

def self.insert_stmt(db)
  db.prepare <<SQL
INSERT INTO Parking2014
VALUES (:ParkingEventId,
        :DeviceId,
        :ArrivalTime,
        :ArrivalTimeSeconds,
        :ArrivalDayOfWeek,
        :ArrivalDayOfMonth,
        :ArrivalMonth,
        :ArrivalYear,
        :DepartureTime,
        :DepartureTimeSeconds,
        :DepartureDayOfWeek,
        :DepartureDayOfMonth,
        :DepartureMonth,
        :DepartureYear,
        :Duration,
        :PermittedDuration,
        :StreetMarker,
        :SignPlateId,
        :Sign,
        :Area,
        :AreaName,
        :StreetId,
        :StreetName,
        :BetweenStreet1Id,
        :BetweenStreet1Description,
        :BetweenStreet2Id,
        :BetweenStreet2Description,
        :SideOfStreet,
        :SideCode,
        :SideName,
        :BayID,
        :InViolation);
SQL
end

def self.permitted_duration(sign)
  if m = sign.match(/^P[\/ ]{0,2}(\d+)/)
    m[1] * SECONDS_IN_MINUTE
  elsif m = sign.match(/^(\d)\s?P/)
    m[1] * SECONDS_IN_HOUR
  elsif sign[0..3] == '1/2P'
    SECONDS_IN_HOUR / 2
  elsif sign[0..3] == '1/4P'<commit_msg>Fix sign handling in sqlite loader<commit_after>#!/usr/bin/env ruby

require 'csv'
require 'sqlite3'
require 'date'

SECONDS_IN_MINUTE = 60
SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60
SECONDS_IN_DAY = SECONDS_IN_HOUR * 24

DateTimeBits = Struct.new(:seconds_since_midnight,
                          :day_of_week,
                          :day_of_month,
                          :month,
                          :year)

def self.seconds_since_midnight(dt)
  (dt - dt.to_date) * SECONDS_IN_DAY
end

def self.insert_stmt(db)
  db.prepare <<SQL
INSERT INTO Parking2014
VALUES (:ParkingEventId,
        :DeviceId,
        :ArrivalTime,
        :ArrivalTimeSeconds,
        :ArrivalDayOfWeek,
        :ArrivalDayOfMonth,
        :ArrivalMonth,
        :ArrivalYear,
        :DepartureTime,
        :DepartureTimeSeconds,
        :DepartureDayOfWeek,
        :DepartureDayOfMonth,
        :DepartureMonth,
        :DepartureYear,
        :Duration,
        :PermittedDuration,
        :StreetMarker,
        :SignPlateId,
        :Sign,
        :Area,
        :AreaName,
        :StreetId,
        :StreetName,
        :BetweenStreet1Id,
        :BetweenStreet1Description,
        :BetweenStreet2Id,
        :BetweenStreet2Description,
        :SideOfStreet,
        :SideCode,
        :SideName,
        :BayID,
        :InViolation);
SQL
end

def self.permitted_duration(sign)
  return 0 unless sign

  if m = sign.match(/^P[\/ ]{0,2}(\d+)/)
    m[1].to_i * SECONDS_IN_MINUTE
  elsif m = sign.match(/^(\d)\s?P/)
    m[1].to_i * SECONDS_IN_HOUR
  elsif sign[0..3] == '1/2P'
    SECONDS_IN_HOUR / 2
  elsif sign[0..3] == '1/4P'
{'fraction_non_alphanumeric': 0.10724365004703669, 'fraction_numerical': 0.017873941674506115, 'mean_word_length': 2.0526315789473686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7610552', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1135, 'n_words': 190}