def main(): """ the utility """ print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STRING) except RuntimeError, error_message: exit_on_failure(error_message[0])
def check_files(cmds, file_keys): """ creates a list of files to plot arguments: cmds: ((string)list)the list of command imputs file_keys: ((string)list)the keys that might contain files returns: a list of valid files """ count = 0 files = [] for key in file_keys: try: #~ if cmds[key] == "" and key != "--data_0": #~ continue if not (check_file(cmds[key])): print_center("ERROR: invalid data_file, " + cmds[key]) exit_on_failure() else: count += 1 files.append(cmds[key]) except KeyError: if (count == 0) : raise KeyError, "no files indicated" #print_center("ERROR: no files indicated", '*') #print_center("use --data_0 as flag for a singal file") #exit_on_failure() else: continue return files
def main(): """ main function """ print_center(UTILITY_TITLE, "-") try: commands = csva.ArgClass(FLAGS, (), HELP_STRING) except RuntimeError, (ErrorMessage): exit_on_failure(ErrorMessage[0])
def main(): """ the utility """ print "<<<USE CRLink.py IT IS A NEWER VERSION OF THIS PROGRAM>>>" return print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STRING) except RuntimeError, error_message: exit_on_failure(error_message[0])
def save_plot(f_name): """ save plot to file of f_name arguments: f_name: (string) name of the file """ csvu.print_center("+++ saving plot to " + f_name + " +++") plt.savefig(f_name, bbox_inches='tight')
def csv_plotter(): """ this is the csv plotter utility this functon acts like main """ print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STRING) except RuntimeError, error_message: exit_on_failure(error_message[0])
def get_ip(): """ gets the ip adderess from a file """ print_center(UTILITY_TITLE, "-") try: inputs = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP) except RuntimeError, error_message: exit_on_failure(error_message[0])
def precip_check(p_dates, p_vals, at_dates, at_vals, interval, cutoff): """ this function checks to see if preciptation values lie with in the given date and temperature values. If they do they are written to a new array as is: else bad_val is written arguments: p_dates: ((datetime) list)precip date array p_vals: ((float) list)precip value array at_dates: ((datetime) list)air temerature date array at_vals: ((float) list)air temerature value array start: (datetime) the start date end: (datetime) the end date cutoff: (float) the cutoff temperature returns an array of corrected precip values """ bad_val = 6999 o_val = [] index = 0 while (index < len(p_dates)): if not(p_dates[index] == at_dates[index]): print_center("dates do not match for precipitation and air temp" ,'*') exit_on_failure() # how to handle this? print p_dates[index], p_vals[index], at_dates[index], at_vals[index] date = p_dates[index].replace(year = 1004) if not(csvd.is_in_interval(date, interval)): o_val.insert(index, bad_val) elif (at_vals[index] < cutoff): o_val.insert(index, bad_val) else: o_val.insert(index, p_vals[index]) index += 1 return o_val
def prompt(c): """ an interactiveprompt for communicating with the data logger""" print_center("interactive prompt") while True: cmd = raw_input(">>> ") cmd_list = cmd.split(' ') if cmd_list[0] == "exit": print "So long, and thanks for all the fish!" return elif cmd_list[0] == "info": print c.info() elif cmd_list[0] == "help": print "dont panic" elif cmd_list[0] == "download": print cmd_list[1] elif cmd_list[0] == "upload": print cmd_list[1] elif cmd_list[0] == "host": print cmd_list[1] elif cmd_list[0] == "port": print cmd_list[1] elif cmd_list[0] == "earth": print "mostly harmless" elif cmd_list[0] == "milliways": print "the resterant at the end of the universe" elif cmd_list[0] == '*': if cmd_list[1] == '6' and cmd_list[2] == '9': print "42 " #(the universe may be fundamentally flawed)" else: print str((int(cmd_list[1])*int(cmd_list[2]))) elif cmd_list[0] == '+': print str((int(cmd_list[1])+int(cmd_list[2]))) elif cmd_list[0] == '-': print str((int(cmd_list[1])-int(cmd_list[2]))) elif cmd_list[0] == '/': print str((int(cmd_list[1])/int(cmd_list[2])))
def main(): """ the utility """ print "<<<USE CRLink.py IT IS A NEWER VERSION OF THIS PROGRAM>>>" return print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STRING) except RuntimeError, error_message: exit_on_failure(error_message[0]) if commands.is_missing_flags(): for items in commands.get_missing_flags(): print_center(" ERROR: flag <" + items + "> is required ", "*") exit_on_failure() #~ if not commands: #~ #~ c = LoggerLink() #~ prompt(c) #~ else: #~ if not ("--action" in commands.keys()): #~ print_center("Error: no action given", "*") #~ exit_on_failure() if("--port" in commands.keys() and "--host" in commands.keys() ): c = LoggerLink(commands['--host'], commands["--port"])
--enddate: the end date (optional) --cutoff: the cutoff temperature (optional) """ def main(): """ the utility """ print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STRING) except RuntimeError, error_message: exit_on_failure(error_message[0]) if commands.is_missing_flags(): for items in commands.get_missing_flags(): print_center(" ERROR: flag <" + items + "> is required ", "*") exit_on_failure() try: at_file = csvf.CsvFile(commands["--at_file"], True) p_in_file = csvf.CsvFile(commands["--precip_infile"], True) except IOError: print_center("ERROR: a required file was not found", '*') exit_on_failure() cutoff = commands.get_command_value("--cutoff", get_cutoff) interval = csvd.make_interval( commands.get_command_value("--startdate" , start_date), commands.get_command_value("--enddate" , end_date)) print interval p_in_file[1] = precip_check(p_in_file[0], p_in_file[1], at_file[0],
def main(): """ main function """ print_center(UTILITY_TITLE, '-') try: commands = csva.ArgClass(FLAGS, (), HELP_STRING) except RuntimeError, (error_message): exit_on_failure(error_message[0]) try: my_file = csvf.CsvFile(commands["--infile"], True) my_steps = csvf.CsvFile(commands["--stepfile"], True) except IOError: print_center("ERROR: a required file was not found", '*') exit_on_failure() my_file[1] = step_function(my_file.get_dates(), my_file[1], my_steps.get_dates(), my_steps[1]) my_file.save(commands["--outfile"]) exit_on_success() class StepFunctionUtility(util.utility_base): """ this class is the setp function utility class """ def __init__(self, title = UTILITY_TITLE, r_args = FLAGS, o_args = (), help = HELP_STRING): """ initilizes the utility
else: return 0 def main(): """ main function """ print_center(UTILITY_TITLE, "-") try: commands = csva.ArgClass(FLAGS, (), HELP_STRING) except RuntimeError, (ErrorMessage): exit_on_failure(ErrorMessage[0]) if commands.is_missing_flags(): for items in commands.get_missing_flags(): print_center(" ERROR: flag <" + items + "> is required ", "*") exit_on_failure() to_utc = commands.get_command_value("--timezone", interp_tz) try: my_file = csvf.CsvFile(commands["--in_file"]) except IOError: print_center("ERROR: input file was not found", '*') exit_on_failure() header = my_file.get_header() dates = my_file.get_dates() delta = timedelta(hours = 9*(to_utc)) if to_utc == 1:
note: use --short or --insitu, not both """ def main(): """the utility""" print_center(UTILITY_NAME, '-') try: commands = csva.ArgClass(REQ_FLAGS, OPT_FLAGS, HELP_STR) except RuntimeError, (error_message): exit_on_failure(error_message[0]) if commands.is_missing_flags(): for items in commands.get_missing_flags(): print_center(" ERROR: flag <" + items + "> is required ", "*") exit_on_failure() try: in_file = csvf.CsvFile(commands["--input"], True) except IOError: print_center("ERROR: a required file was not found", '*') exit_on_failure() try: xl_data = fetch_excel_data(commands["--insitu"]) except KeyError: try: xl_data = fetch_excel_data(commands["--short"]) except KeyError: print_center("ERROR: an adjustment file has not been provided", "*")