comparison validate_temperature_data.py @ 9:9f4f850c472d draft

Uploaded
author greg
date Tue, 27 Nov 2018 10:14:40 -0500
parents 119c30a504db
children 1ce61b5b58d5
comparison
equal deleted inserted replaced
8:119c30a504db 9:9f4f850c472d
71 accumulated_msgs = "" 71 accumulated_msgs = ""
72 # Parse the input file, skipping the header, and validating 72 # Parse the input file, skipping the header, and validating
73 # that each data line consists of 31 comma-separated items. 73 # that each data line consists of 31 comma-separated items.
74 if args.data_type == "normals": 74 if args.data_type == "normals":
75 input_file = args.input_normals 75 input_file = args.input_normals
76 header = NORMALS_HEADER
77 last_doy = 0 76 last_doy = 0
78 num_normals_rows = 0 77 num_normals_rows = 0
79 else: 78 else:
80 input_file = args.input_actuals 79 input_file = args.input_actuals
81 header = ACTUALS_HEADER
82 with open(input_file, "r") as ih: 80 with open(input_file, "r") as ih:
83 for i, line in enumerate(ih): 81 for i, line in enumerate(ih):
84 line = line.rstrip("\r\n") 82 line = line.rstrip("\r\n")
85 if i == 0:
86 if line != header:
87 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % header)
88 continue
89 items = line.split(",") 83 items = line.split(",")
90 if args.data_type == "normals": 84 if args.data_type == "normals":
91 num_normals_rows += 1 85 num_normals_rows += 1
86 if i == 0:
87 if line != NORMALS_HEADER:
88 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % NORMALS_HEADER)
89 continue
92 if i > 367: 90 if i > 367:
93 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and 366 data lines).") 91 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and 366 data lines).")
94 stop_error(accumulated_msgs) 92 stop_error(accumulated_msgs)
95 if len(items) != 10: 93 if len(items) != 10:
96 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items))) 94 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items)))
127 tmin = items[8].strip() 125 tmin = items[8].strip()
128 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 126 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
129 tmax = items[9].strip() 127 tmax = items[9].strip()
130 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 128 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")
131 else: 129 else:
130 if i == 0:
131 if line != ACTUALS_HEADER:
132 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % ACTUALS_HEADER)
133 continue
132 if i > 367: 134 if i > 367:
133 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).")
134 stop_error(accumulated_msgs) 136 stop_error(accumulated_msgs)
135 if len(items) != 6: 137 if len(items) != 6:
136 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 6)." % (i, len(items))) 138 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 6)." % (i, len(items)))