comparison trafficintelligence/utils.py @ 1030:aafbc0bab925

moved method around to avoid cross-dependencies
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 19 Jun 2018 10:04:52 -0400
parents c6cf75a2ed08
children 045cb04ad7b8
comparison
equal deleted inserted replaced
1029:c6cf75a2ed08 1030:aafbc0bab925
13 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve, dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit 13 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve, dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit
14 from numpy.random import permutation as nppermutation 14 from numpy.random import permutation as nppermutation
15 from pandas import DataFrame, concat 15 from pandas import DataFrame, concat
16 import matplotlib.pyplot as plt 16 import matplotlib.pyplot as plt
17 17
18 from trafficintelligence.storage import openCheck
19
20 datetimeFormat = "%Y-%m-%d %H:%M:%S" 18 datetimeFormat = "%Y-%m-%d %H:%M:%S"
21 19
22 sjcamDatetimeFormat = "%Y_%m%d_%H%M%S"#2017_0626_143720 20 sjcamDatetimeFormat = "%Y_%m%d_%H%M%S"#2017_0626_143720
21
22 #########################
23 # txt files
24 #########################
25
26 commentChar = '#'
27
28 delimiterChar = '%';
29
30 def openCheck(filename, option = 'r', quitting = False):
31 '''Open file filename in read mode by default
32 and checks it is open'''
33 try:
34 return open(filename, option)
35 except IOError:
36 print('File {} could not be opened.'.format(filename))
37 if quitting:
38 from sys import exit
39 exit()
40 return None
41
42 def readline(f, commentCharacters = commentChar):
43 '''Modified readline function to skip comments
44 Can take a list of characters or a string (in will work in both)'''
45 s = f.readline()
46 while (len(s) > 0) and s[0] in commentCharacters:
47 s = f.readline()
48 return s.strip()
49
50 def getLines(f, delimiterChar = delimiterChar, commentCharacters = commentChar):
51 '''Gets a complete entry (all the lines) in between delimiterChar.'''
52 dataStrings = []
53 s = readline(f, commentCharacters)
54 while len(s) > 0 and s[0] != delimiterChar:
55 dataStrings += [s.strip()]
56 s = readline(f, commentCharacters)
57 return dataStrings
23 58
24 ######################### 59 #########################
25 # Strings 60 # Strings
26 ######################### 61 #########################
27 62