def training_times(data_dict, max_time): """ Crée un programme d'entrainement sur la base des éléments choisis et un temps maximum. """ keys = data_dict.keys() weights = np.array([data_dict[k][2] for k in keys]) rv = initialize_named_choices(keys, weights) sequence = rv.rvs(size=100) time_left = max_time text = "\nSéance sur %d minutes : \n" % max_time for s in sequence: if time_left > 0: key = keys[s] name = data_dict[key][0] dur = min(data_dict[key][1], time_left) time = stats.poisson.rvs(dur, size=1) time_left = time_left - time if time > 0: text = text + " - %s : %d minutes\n" % (name, time) else: break return text
def sequence(step_list): """ Crée un programme d'entrainement sur la base des éléments choisis et un temps maximum. """ text = "\nDéroulé de votre séance : \n" # go through the steps for step in step_list: parts = step[0] max_time = step[1] unite = step[2] n_parts = len(parts) # go through the parts in the step dur_parts = [] for ipart in xrange(n_parts): # read the options part = parts[ipart] data_dict = read_data_file(part) keys = data_dict.keys() weights = np.array([data_dict[k][2] for k in keys]) rv = initialize_named_choices(keys, weights) # select an option and get its name and mean duration el_index = rv.rvs(size=1) key = keys[el_index] name = data_dict[key][0] dur = min(data_dict[key][1], max_time) dur_parts.append(dur) if ipart == 0: text = text + " - %s" % name else: text = text + " %s" % name time = stats.poisson.rvs(min(dur_parts), size=1) text = text + " pour %d %s\n" % (time, unite) return text
email_file = 'email_jeu_TL.txt' def make_message(noms_role, rv_role, noms_epaisseur, rv_epaisseur): msg = "Le jeu commence... \n\n" + \ "Role : %s pour %d heures avec couche %s.\n" % \ (noms_role[rv_role.rvs(size=1)], stats.poisson.rvs(mu_duree), noms_epaisseur[rv_epaisseur.rvs(size=1)]) return msg if __name__ == '__main__': noms_role = ['AB', 'DL'] noms_epaisseur = ['jetable fine', 'jetable épaisse', 'lavable'] mu_duree = 4 w_role = np.array([0.25, 0.75]) w_epaisseur = np.array([0.4, 0.4, 0.2]) rv_role = bm_prob.initialize_named_choices(noms_role, w_role) rv_epaisseur = bm_prob.initialize_named_choices(noms_epaisseur, w_epaisseur) msg = make_message(noms_role, rv_role, noms_epaisseur, rv_epaisseur) bm_io.send_message(email_file, msg, 'Proposition de jeu pour TL') print "Proposition de jeu envoyée..."
if __name__ == '__main__': noms_att = ['couchée', 'débout', 'assise', 'à genou'] noms_instrum = ['fessée à la main', 'fessée à la brosse', 'fessée à la cravache', 'fessée à la canne anglaise', 'fessée avec la latte', 'stimulation à la roulette', 'stimulation au vibro'] noms_acc = ['rien', 'pinces aux seins', 'culotte en string', 'plug'] mu_att = 10 mu_instrum = 15 w_att = bm_prob.setup_uniform_weights(noms_att) w_instrum = bm_prob.setup_ordered_weights(noms_instrum) w_acc = bm_prob.setup_ordered_weights(noms_acc) rv_att = bm_prob.initialize_named_choices(noms_att, w_att) rv_instrum = bm_prob.initialize_named_choices(noms_instrum, w_instrum) rv_acc = bm_prob.initialize_named_choices(noms_acc, w_acc) msg = make_message(noms_att, rv_att, noms_instrum, rv_instrum, noms_acc, rv_acc) bm_io.send_message(email_file, msg, "Proposition de jeu pour Britannie") print "Proposition de jeu envoyée..."
def setUp(self): n_choices = 10 self.names = np.arange(n_choices) self.weights = np.random.random(n_choices) self.norm_weights = bm_prob.normalize_weights(self.weights) self.prob_fn = bm_prob.initialize_named_choices(self.names, self.weights)