comparison validate_temperature_data.py @ 15:13de3d5839ac draft

Uploaded
author greg
date Tue, 27 Nov 2018 10:54:40 -0500
parents 59b9339c2ed6
children 304b46e9a34b
comparison
equal deleted inserted replaced
14:59b9339c2ed6 15:13de3d5839ac
126 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 126 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
127 tmax = items[9].strip() 127 tmax = items[9].strip()
128 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 128 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")
129 else: 129 else:
130 if i == 0: 130 if i == 0:
131 try:
132 last_doy = int(doy)
133 except Exception:
134 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains an invalid DOY (%s must be an integer)." % (i, doy))
135 stop_error(accumulated_msgs)
136 if line != ACTUALS_HEADER: 131 if line != ACTUALS_HEADER:
137 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % ACTUALS_HEADER) 132 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % ACTUALS_HEADER)
138 continue 133 continue
139 if i > 367: 134 if i > 367:
140 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and no more than 366 data lines).") 135 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and no more than 366 data lines).")
149 date_string = items[2].strip() 144 date_string = items[2].strip()
150 accumulated_msgs = validate_date_string(i, date_string, accumulated_msgs) 145 accumulated_msgs = validate_date_string(i, date_string, accumulated_msgs)
151 doy = items[3].strip() 146 doy = items[3].strip()
152 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy") 147 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy")
153 # Make sure the DOY values are consecutive. 148 # Make sure the DOY values are consecutive.
154 try: 149 if i == 1:
155 if int(doy) != (last_doy + 1): 150 try:
156 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains a DOY (%s) that is not conexcutive." % (i, doy)) 151 last_doy = int(doy)
157 stop_error(accumulated_msgs) 152 except Exception:
158 except Exception: 153 pass
159 # The error for an invalid integer was captured above. 154 else:
160 pass 155 try:
156 if int(doy) != (last_doy + 1):
157 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains a DOY (%s) that is not conexcutive." % (i, doy))
158 stop_error(accumulated_msgs)
159 except Exception:
160 # The error for an invalid integer was captured above.
161 pass
161 last_doy += 1 162 last_doy += 1
162 tmin = items[4].strip() 163 tmin = items[4].strip()
163 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 164 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
164 tmax = items[5].strip() 165 tmax = items[5].strip()
165 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 166 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")