def post(self): """ Create a new Experiment (with Treatments and Properties) based on the POSTed form data. The format is as follows: exp_name = main Experiment name exp_description = main Experiment description exp_instructions = Instructions on how to test the treatments to be given to the participants exp_device = Which device(s) are allowed for this experiment treat##_name = the name of treatment ## treat##_prop##_name = the name of a property to be changed for treatment ## treat##_prop##_value = the value that property ## will be set to for treatment ## There can be any number of treatments/properties, but there can be no missing values, (ie: a property name without a value) or the creation will fail. """ experiment = self.parse() if not experiment: self.redirect('error') else: exp = Experiment() exp.name = experiment.get('name') exp.description = experiment.get('description') exp.instructions = experiment.get('instructions') exp.device = experiment.get('device') exp.owner = experiment.get('owner') exp.experiment_type = experiment.get('experiment_type') exp.put() # Adding each treatment in turn for treatment in experiment.get('treatments'): t = Treatment(parent=exp.key()) t.name = treatment.get('name') t.put() for property in treatment.get('properties'): p = Property(parent=t.key()) p.name = property.get('name') p.value = property.get('value') p.put() self.redirect('view?exp_key=%s' % exp.key())
def experiment_clone(expid=None): if not expid: expid = request.cookies.get('project') if not expid: return render_template('error.html',message="Proyecto no seleccionado",recent=recent.get()) expid=int(expid) exp_=db_session.query(Experiment).get(expid) if not exp_: return render_template('error.html',message="Experimento no definido",recent=recent.get()) exp=Experiment() exp.name="CLONE:"+exp_.name exp.definition=exp_.definition exp.description=exp_.description exp.instructions=exp_.instructions exp.invitation=exp_.invitation exp.reinvitation=exp_.reinvitation db_session.add(exp) db_session.commit() return redirect(url_for('.experiment_info',expid=exp.id))
def main(): user = User() datasets = [] experiments = [] invalid_sensors_error = False file_paths = user.choose_files() ###Dataset Creation for i, path in enumerate(file_paths): dataset = Dataset(path) if (len(dataset.invalid_sensors()) == 0): datasets.append(dataset) logger.info("All sensors OK in file {}".format(i)) else: dataset.report_invalid_sensors() invalid_sensors_error = True if invalid_sensors_error: print( "Please check if the column names of the CSV files are spelled correctly! If they are correct, please add the new sensors in the database!" ) return logger.print_chosen_files(file_paths) logger.print_available_rocks(api_handler.rocks) for i, dataset in enumerate(datasets): experiment = Experiment(dataset) experiment.rock_id = user.choose_rock(dataset.filepath) experiment.description = user.write_description() experiment.start_time = user.set_date() dataset.calculate_checksum() experiments.append(experiment) chunk_size = 500000 while True: experiment_addded = False continue_with_upload = user.continue_with_upload() if continue_with_upload: try: for experiment in experiments: logger.success("\n\nUploading file {}.".format( experiment.dataset.filepath)) nr_of_chunks = experiment.dataset.file_length // chunk_size if experiment.dataset.file_length % chunk_size == 0 else experiment.dataset.file_length // chunk_size + 1 with open(experiment.dataset.filepath) as f: for i in tqdm(range(nr_of_chunks)): chunk_response = api_handler.send_file_chunk( experiment, f, chunk_size=chunk_size) if chunk_response.text == 'DATASET_ALREADY_IN_DB': logger.error( "\n\nThis dataset is already stored in database! Stopping upload!" ) break if chunk_response.text == 'DATASET_ALREADY_IN_DB': continue metadata_response = api_handler.send_metadata(experiment) if metadata_response.text == "METADATA_RECEIVED": logger.success("File {} uploaded!".format( experiment.dataset.filepath)) add_experiment_response = api_handler.add_experiment( experiment) if add_experiment_response.text == 'EXPERIMENT_BEING_ADDED_TO_THE_DB': logger.success( "The uploaded dataset is being written in the database. It may take some time. You can check its progress in the web application!" ) else: print( "An error occred while inserting the dataset in the database!" ) except Exception as exc: logger.error("ERROR: " + str(exc)) logger.input("Press Enter to continue!") break elif continue_with_upload == False: exit()