示例#1
0
def simple_sensorHub(params):
    params['subject'] =  "SensorHub Graphic "
    email_response = ""
    path_real, database_name = utils.download_database(params['filename'], full_path = False)
    only_name = database_name[:database_name.rfind(".")]
    params["all_time"] = utils.get_datetime() #TIME
    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "Exporting data (Sensor Hub) ..."
        export_csv ="SensorHub_%s" % (only_name+".csv")
        ExportSensorHub().run(path_real+database_name, path_real+export_csv)
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("CSV conversion",params["a_func"])
    email_response += "OK\n"
    email_response += "\n CSV file = "+utils.create_link(params['KEY_IML'],str(path_real),str(export_csv))+"\n\n\n"
    email_response += time_txt

    try:
        email_response += "Building Graphic (Sensor Hub) ..."
        path_graphic ="sensor_hub_%s" % (only_name+".pdf")
        SensorHubGraphic().run(path_real+export_csv,path_real+path_graphic)
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("Graphic creation",params["a_func"])
    email_response += "OK\n"
    email_response += "\n Graphic = "+utils.create_link(params['KEY_IML'],str(path_real),str(path_graphic))+"\n\n\n"
    email_response += time_txt

    email_response += utils.end_func("All process",params["all_time"])
    return utils.response_email(params['email'],params['subject'], email_response)
示例#2
0
def filter_simple_wifi(params):
    params['subject'] =  "Filter WIFI Graphic "
    email_response = utils.show_info(params) + "\n"
    path_real, database_name = utils.download_database(params['filename'], full_path = False)
    only_name = database_name[:database_name.rfind(".")]
    params["all_time"] = utils.get_datetime() #TIME
    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "Exporting data (WIFI) ..."
        export_csv ="filter_wifi%s" % (only_name+".csv")
        wifi_list_mac, wifi_list_name = utils.parse_wifi_list(params['wifi_list'])
        ExportWifi(wifi_list_mac,wifi_list_name,params['is_blacklist']).run(path_real+database_name,path_real+export_csv)
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("CSV conversion",params["a_func"])
    email_response += "OK\n"
    email_response += "\n CSV file = "+utils.create_link(params['KEY_IML'],str(path_real),str(export_csv))+"\n\n\n"
    email_response += time_txt

    try:
        email_response += "Building Graphic (Bluetooth) ..."
        path_graphic ="filter_wifi_%s" % (only_name+".pdf")
        WifiGraphic().run(path_real+export_csv,path_real+path_graphic)
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("Graphic creation",params["a_func"])
    email_response += "OK\n"
    email_response += "\n Graphic = "+utils.create_link(params['KEY_IML'],str(path_real),str(path_graphic))+"\n\n\n"
    email_response += time_txt

    email_response += utils.end_func("All process",params["all_time"])
    return utils.response_email(params['email'],params['subject'], email_response)
示例#3
0
def exec_ML_1(params):
    params['subject'] = "Machine Learning - Results"
    email_response = utils.show_info(params) + "\n"
    try:
        email_response += "download database ..."
        path_real, database_name = utils.download_database(params['filename'], full_path = False)
    except Exception as e:
        return utils.get_error(e, params)

    email_response += "OK\n"
    email_response += "\n Database = "+utils.create_link(params['KEY_IML'],str(path_real),str(database_name))+"\n\n\n"
    params['path_real'] = path_real
    params['database_name'] = database_name

    params["only_database_name"] = database_name[:database_name.rfind(".")]
    params["all_time"] = utils.get_datetime() #TIME
    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "Converting csv ..."
        params["csvfile"] = params["only_database_name"]+".csv"
        export_csv.run(
            inputfile=path_real+database_name,
            outputfile=path_real+params["csvfile"],
            bluetooth=params['bluetooth'],
            wifi=params['wifi'],
            sensorhub=params['optimzation_sensor_hub'],
            battery=True if params['optimzation_sensor_hub'] else False ,
            optimize=params['optimzation_sensor_hub'],
            )
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("CSV conversion",params["a_func"])
    email_response += "OK\n"
    email_response += "\n CSV file = "+utils.create_link(params['KEY_IML'],str(path_real),str(params["csvfile"]))+"\n\n"
    email_response += time_txt

    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "PreProcessing ..."
        df = pd.read_csv(open(path_real+params["csvfile"],"r"), sep=',', header=0, index_col=0)
        pre_processing = pre.PreProcessing(df,norm=params['optimzation_sensor_hub'])
        df = pre_processing.build()
        df.to_csv(path_real+"pre_processing"+params["csvfile"], sep=',', encoding='utf-8', header=True)
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("PreProcessing",params["a_func"])
    email_response += "OK\n"
    email_response += "\n CSV PreProcessing = "+utils.create_link(params['KEY_IML'],str(path_real),path_real+"pre_processing"+params["csvfile"])+"\n\n"
    email_response += time_txt
    params['csvpreprocessing'] = path_real+"pre_processing"+params["csvfile"]

    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "Clustering ..."
        labels, n_clusters = Clustering(df, mode="fixed_k", n_clusters=int(params['number'])).clusterize()
        timestamp = list(df.index)
        params['csvcluster'] = str(params['number'])+"clusters"+params["only_database_name"]+".csv"
        with open(path_real+params['csvcluster'], 'w') as f:
            f.write("timestamp,clusters\n")
            for i in range(len(labels)):
                f.write("{},{}\n".format(timestamp[i],labels[i]))
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("Clustering",params["a_func"])
    email_response += "OK\n"
    email_response += "\n CSV MachineLearning = "+utils.create_link(params['KEY_IML'],str(path_real),str(params['csvcluster']))+"\n\n"
    email_response += time_txt


    params["a_func"] = utils.get_datetime() #TIME
    try:
        email_response += "Creating graphic..."
        params['pdfgraphic'] = (params["only_database_name"]+".pdf").replace("(","").replace(")","")
        print "Rscript machine_learning/pdf/pdf_lines.R \""+path_real+params['csvcluster']+"\" \""+path_real+params['pdfgraphic']+"\""
        os.system("Rscript machine_learning/pdf/pdf_lines.R \""+path_real+params['csvcluster']+"\" \""+path_real+params['pdfgraphic']+"\"")
    except Exception as e:
        return utils.get_error(e, params)

    time_txt = utils.end_func("Graphic creation",params["a_func"])
    email_response += "OK\n"
    email_response += "\n Graphic = "+utils.create_link(params['KEY_IML'],str(path_real),str(params['pdfgraphic']))+"\n\n"
    email_response += time_txt


    print email_response
    email_response += utils.end_func("All process",params["all_time"])
    return utils.response_email(params['email'],"Machine Learning - Results", email_response)
示例#4
0
def download_database(params):
    params['subject'] =  "Database - "
    path_real, database_name = utils.download_database(params['filename'], full_path = False)
    utils.response_email(params['email'] , params['subject'], utils.create_link(params['KEY_IML'],path_real,database_name))