Kategorie Sensor<
#Purpose:
# empfängt => 1) den Text, der Informationen über 1 Sensor enthält
# analysiert => 2) das Info und speichert es als Eigenschaften des obj
# durch den Struct Gegenstand
# hat => 3) die Methode, zum der Daten in eine .csv Akte zu drücken
#
Struct.new (: s_id,
: s_name,
: s_dataSourceId,
: s_tmcId,
: s_type,
: s_status,
: s_speed,
: s_volume,
: s_longVolume,
: s_occupancy,
: s_lastUpdated)
def fill_struct (s_text)
@arr = Array.new (11)
@arr [0] = (? <=id: ").*? (? =")/
@arr [1] = (? <=name: ").*? (? =")/
@arr [2] = (? <=dataSourceId: ").*? (? =")/
@arr [3] = (? <=tmcID: ").*? (? =")/
@arr [4] = (? <=type: ").*? (? =")/
@arr [5] = (? <=status: ").*? (? =")/
@arr [6] = (? <=speed: ). *? (? =,)/
@arr [7] = (? <=volume: ). *? (? =,)/
@arr [8] = (? <=longVolume: ). *? (? =,)/
@arr [9] = (? <=occupancy: ). *? (? =,)/
@arr [10] = (? <=lastUpdated: neues Datum \ (").*? (? =")/
self.s_id = s_text.scan (@arr [0]) [0]
self.s_name = s_text.scan (@arr [1]) [0]
self.s_dataSourceId = s_text.scan (@arr [2]) [0]
self.s_tmcId = s_text.scan (@arr [3]) [0]
self.s_type = s_text.scan (@arr [4]) [0]
self.s_status = s_text.scan (@arr [5]) [0]
self.s_speed = s_text.scan (@arr [6]) [0] .to_i
self.s_volume = s_text.scan (@arr [7]) [0] .to_i
self.s_longVolume = s_text.scan (@arr [8]) [0] .to_i
self.s_occupancy = s_text.scan (@arr [9]) [0] .to_i
self.s_lastUpdated = s_text.scan (@arr [10]) [0]
Ende
def mysql_out (db_mysql)
Ende
def csv_out (f_output)
self.each tun |I|
f_output.print I, „,“
Ende
f_output.print „\ n“
Ende
Ende
#Objective -
# =>
# =>
# =>
# =>
def collect_stats (s_html, s_path)
rgx_pass_1 = /id. *?}/m #1. verursachen ein RegExp, um einzeln zu erhalten
# Resultate
s_file = geöffnete (s_html) .read #2. Durchlaufweb site in s_file Variable
b = [] #3. verursachen eine leere Reihe, um zu halten
# Sensor-Gegenstände
s_file.scan (rgx_pass_1) .each tun |I| #4. Scan-Schnur für RegExp Gleiche
# A) Durchlauf jedes Resultat
a = Sensor.new #5. verursachen neuen Sensor-Gegenstand
a.fill_struct (i) rufen #6. die Füllemethode des Gegenstandes hervor
# A) mit dem Resultat
b< |