comparison validate_temperature_data.py @ 7:c5004164d035 draft

Uploaded
author greg
date Tue, 27 Nov 2018 10:09:20 -0500
parents 418a11822c5a
children 119c30a504db
comparison
equal deleted inserted replaced
6:418a11822c5a 7:c5004164d035
53 def validate_mmdd(line_no, mmdd, accumulated_msgs): 53 def validate_mmdd(line_no, mmdd, accumulated_msgs):
54 try: 54 try:
55 datetime.datetime.strptime(mmdd, '%m-%d') 55 datetime.datetime.strptime(mmdd, '%m-%d')
56 return accumulated_msgs 56 return accumulated_msgs
57 except ValueError: 57 except ValueError:
58 # Handle Feb 29.
59 items = mmdd.split("-")
60 try:
61 month = int(items[0])
62 day = int(items[1])
63 if month == 2 and day == 29:
64 return accumulated_msgs
65 except Exception
66 # Error message accumulated below.
67 pass
58 return add_error_msg(accumulated_msgs, "Line %d contains an incorrect date format (%s must be mm-dd)." % (line_no, mmdd)) 68 return add_error_msg(accumulated_msgs, "Line %d contains an incorrect date format (%s must be mm-dd)." % (line_no, mmdd))
59 69
60 70
61 accumulated_msgs = "" 71 accumulated_msgs = ""
62 # Parse the input file, skipping the header, and validating 72 # Parse the input file, skipping the header, and validating
76 if line != header: 86 if line != header:
77 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % header) 87 accumulated_msgs = add_error_msg(accumulated_msgs, "The header is invalid, must be %s" % header)
78 continue 88 continue
79 items = line.split(",") 89 items = line.split(",")
80 if args.data_type == "normals": 90 if args.data_type == "normals":
91 num_normals_rows += 1
81 if i > 367: 92 if i > 367:
82 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and 366 data lines).") 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).")
83 stop_error(accumulated_msgs) 94 stop_error(accumulated_msgs)
84 if len(items) != 10: 95 if len(items) != 10:
85 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items))) 96 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items)))
115 pass 126 pass
116 tmin = items[8].strip() 127 tmin = items[8].strip()
117 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 128 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
118 tmax = items[9].strip() 129 tmax = items[9].strip()
119 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 130 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")
120 num_normals_rows += 1
121 else: 131 else:
122 if i > 367: 132 if i > 367:
123 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).") 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).")
124 stop_error(accumulated_msgs) 134 stop_error(accumulated_msgs)
125 if len(items) != 6: 135 if len(items) != 6: