def get_log_directory(logtype): log_dir = get_data_path() + '/' + logtype + '/' if not os.path.exists(log_dir): os.makedirs(log_dir) return log_dir
def get_worker_id_who_sent_email(): file_path = get_data_path() + "/email_received_worker_id" worker_id_set = set() with open(file_path) as input_file: for line in input_file: worker_id_set.add(line.strip()) return worker_id_set
def get_Emailgroup(): Emailgroup = set() with open(get_data_path() + '/email_received_worker_id') as input_file: for line in input_file: Emailgroup.add(line.strip()) return list(Emailgroup)
def print_results_to_file(report, result): with open(get_data_path() + "/hit_report2.csv", 'w') as output_file: output_file.write( "S.No, WorkerID, Total labels, Basic cost, Attempting bonus, Email bonus, CompHIT pay, Money to enter\n" ) count = 1 for info in report: output_file.write( str(count) + ", " + ", ".join(str(x) for x in info) + "\n") count += 1 output_file.write(result)
def get_hit_list(): line_number = 0 hit_id_list = list() with open(get_data_path() + '/HITs.txt') as input_file: for line in input_file: line_number += 1 validation = line.strip().split(":")[0] if line_number % 2 == 1 and validation == "Your HIT ID is": hit_id = line.strip().split(":")[1] hit_id_list.append(hit_id.strip()) return hit_id_list
def get_worker_id(): worker_id_list = [] with open(get_data_path() + "/hit_report2.csv") as csvfile: next(csvfile) spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: if row[1].strip(): worker_id_list.append(row[1].strip()) return worker_id_list
def check_money_right(worker_id, total_money): with open(get_data_path() + "/hit_report2.csv") as input_file: header = next(input_file) for line in input_file: info = line.strip().split(", ") workerid = info[1] money = info[7] if (worker_id == workerid) and (total_money == money): print('Paid worker %s: $%s\n' % (worker_id, total_money)) return True print('Your input does not match our calculation.\nPlease re-enter!!') sys.exit(1)
def insert_data(collection_name): mongo_client = MongoClient('localhost', 8081) db = mongo_client.meteor file_path = get_data_path() + "/" + FILE_NAME data = get_data_from_file(file_path) new_collection = db[collection_name] for record in data: q3 = (record[6]).strip().split("\n") q3_labels = dict() for i in range(len(q3_options)): if q3_options[i] in q3: q3_labels[q3_options[i]] = 1 else: q3_labels[q3_options[i]] = -1 document = { 'unitID': record[0], 'messageID': record[1], 'messageText': record[2], 'ID': record[3], 'message-1': record[4], 'message-2': record[5], 'message-3': record[6], 'message1': record[7], 'message2': record[8], 'message3': record[9], 'q1': record[10], 'q2': record[11], 'q3': q3_labels, 'time_text': record[13], 'time_message-1': record[14], 'time_message-2': record[15], 'time_message-3': record[16], 'time_message1': record[17], 'time_message2': record[18], 'time_message3': record[19], 'fitnessFuncValue': random() } new_collection.insert_one(document)