def createMember(self, namespace: str, member: Member, preTitle: str) -> None: assert self.fileHandle self.fileHandle.write("{}`{} {}`\n".format(preTitle, member.printDefinition("{template} {pre} {type}"), member.printDefinition("{name} {post}"))) if member.getProvenance(): self.fileHandle.write("*From {}*\n\n".format(member.getProvenance())) self.fileHandle.write("{}\n".format(self.formatComment(member.getDescription()))) definition = member.getDefinition() # Set the template if len(member.getTemplate()): self.fileHandle.write("#### Template\n") self.fileHandle.write("||||\n") self.fileHandle.write("|---:|:---|:---|\n") for template in member.getTemplate(): self.fileHandle.write("|{}|{}|{}|\n".format(template.get("type"), template.get("name"), template.get("description", ""))) # Set the arguments if definition["args"] and len(member.getArgs()): self.fileHandle.write("#### Parameters\n") self.fileHandle.write("||||\n") self.fileHandle.write("|---:|:---|:---|\n") for arg in member.getArgs(): self.fileHandle.write("|{}|{}|{}|\n".format(arg.get("type"), arg.get("name"), arg.get("description", "")))
def new_member(self, member_name): """ Add a new member with name *member_name* :param member_name: The name of the member. :returns: A Member class, with Members.person populated with name. """ return Member(member_name)
def create_member(): first_name = request.form.get('first_name', '') last_name = request.form.get('last_name', '') if not first_name or not last_name: flash('Both first name and last name need to be specified', 'danger') return render_template('new_member.html', first_name=first_name, last_name=last_name) member = Member(first_name=first_name.strip(), last_name=last_name.strip()) try: member.save() flash('Created new team member %s' % member.name, 'success') except Exception: flash('Failed to create new team member %s' % member.name, 'danger') return redirect(url_for('new_member'))
def get_member(self, member_name): """ Get existing member with name *member_name* :param member_name: The name of the member. :returns: A Member class, with Members.person populated with name. """ return Member(member_name)
def lunch_time(): # seed should be None if it's not specified or an empty string seed = request.args.get('seed') or None # NOTE: There may be a performance issue if there are millions of members all_members = list(Member.all()) return render_template('lunch_time.html', groups=random_group(all_members, seed=seed), seed=seed if seed else '')
def load_tweets(db): members = Member.select().order_by(fn.Random()) for member in members: print("collecting tweets for", member.first_name, member.last_name, member.twitter_account) try: oldest_tweet = member.tweets.order_by(Tweet.twitter_id.asc()).limit(1).get() except Tweet.DoesNotExist: oldest_tweet = None collect_tweets(db, member, oldest_tweet)
def members(member_id=None): member_id = int(member_id) if member_id else None if request.method == 'GET': if member_id: member = Member.build_key(member_id).get() if not member: return "Member %s not found" % member_id, Status.HTTP_404_NOT_FOUND return render_template("member-details.html", member=member) else: members = Member.query().order(-Member.created).fetch() return render_template( "member-list.html", members=members, created=request.args.get('created')) elif request.method in ['PUT', 'POST']: if member_id: member = Member.build_key(member_id).get() if member: member.update(**convert_form_to_member_data(request.form)) member.put() redirect(uri_for("members")) else: return "Member %s not found." % member_id, Status.HTTP_404_NOT_FOUND else: # Create a new member form = NewMemberForm(request.form) member = Member(**convert_form_to_member_data(form)) member.put() sleep(1) # I'm ashamed of myself return redirect(url_for("members", created=member.member_id)) elif request.method == 'DELETE': if member_id: member = Member.build_key(member_id).get() if member: member.key.delete() return jsonify(deleted=member.to_dict()) else: return "Member %s not found." % member_id, Status.HTTP_404_NOT_FOUND else: if request.args.get('force') == 'true': all_members = Member.query().fetch() [m.key.delete() for m in all_members] return jsonify(deleted=[m.to_dict() for m in all_members]) else: return "Please use 'force=true' to delete all members.", Status.HTTP_304_NOT_MODIFIED
def view_member_details(): """ self explanatory """ first, last = Member.ask_name() to_be_or_not = MemberFunc(first, last) if not to_be_or_not.already_member(): print("Member doesnt exist. q to quit or m for main menu") user_input = input() quit_or_menu(user_input) else: to_be_or_not.view_matches()
def addMember(self, data: MutableMapping[str, Any], member: MutableMapping[str, Any]) -> None: if member["__info__"].get("kind", None) in kindToKeep: # Generate the member identifier memberData = self.removeNestedKeyword(member["__info__"], "__info__") identification = Member(memberData).makeIdentifier() data[identification] = data[ identification] if identification in data else {} data[identification] = self.mergeMember(data[identification], member)
def build_member(lr, dropout): model, encoder_model, decoder_model = \ define_nmt(hidden_size, embedding_size, timesteps, en_vocab_size, de_vocab_size, dropout, np.power(10, lr)) return Member(model, param_names=['lr', 'dropout'], tune_lr=True, use_eval_metric='bleu', custom_metrics={ 'bleu': lambda x, y, _: bleu_score_enc_dec( encoder_model, decoder_model, x, y, batch_size) })
def delete_member(): """ self explanatory """ first, last = Member.ask_name() print_stars() to_be_or_not = MemberFunc(first, last) if not to_be_or_not.already_member(): print("Member doesnt exist. q to quit or m for main menu") user_input = input() quit_or_menu(user_input) else: to_be_or_not.view_matches() id_to_del = to_be_or_not.id_to_del() run_del(id_to_del) com_close()
def update_member(): """ self explanatory """ print_stars() print("Previous first and last name to update") print_stars() first_name, last_name = Member.ask_name() to_be_or_not = MemberFunc(first_name, last_name) if not to_be_or_not.already_member(): print("Member doesnt exist. q to quit or m for main menu") user_input = input() quit_or_menu(user_input) else: to_be_or_not.view_matches() id_to_del = to_be_or_not.id_to_del() print("Insert NEW details:") run_update(first_name, last_name, id_to_del) com_close()
def build_member(lr, dropout): ''' Building baseline model using lr and dropout rates passed in terms of parameters For each member we pass our parameters, tune the learning rate, using BLEU as our performance metric. ''' model, encoder_model, decoder_model = \ define_nmt(hidden_size, embedding_size, timesteps, en_vocab_size, de_vocab_size, dropout, np.power(10, lr)) return Member(model, param_names=['lr', 'dropout'], tune_lr=True, use_eval_metric='bleu', custom_metrics={ 'bleu': lambda x, y, _: bleu_score_enc_dec( encoder_model, decoder_model, x, y, batch_size) })
def main(): parser = argparse.ArgumentParser() parser.add_argument("-c", "--count", type=int, default=100, help='Specify # of fake members record to be inserted') args = parser.parse_args() fake = Faker() Member.init() for _ in range(args.count): member = Member(first_name=fake.first_name(), last_name=fake.last_name()) member.save()
def run_update(old_first, old_last, id_to_del): (new_first_name, new_last_name, new_phone_number, new_email) = Member.ask_details() run_sql_script(UPDATE_ID_SQL, (new_first_name, new_last_name, new_phone_number, new_email, old_first, old_last, id_to_del)) print("{0} {1} member updated to database on {2} at {3}".format(new_first_name, new_last_name, date, time_imp()))
def run_insert(): (first_name, last_name, phone_number, email) = Member.ask_details() run_sql_script(INSERT_SQL, (first_name, last_name, phone_number, email, date, date_30)) print("{0} {1} adding to database on {2} at {3}".format(first_name, last_name, date, time_imp()))
from members import Member from random_group import random_group app = Flask(__name__) # TODO: Specify secret_key via env variable app.secret_key = '28cfe91e907f' logging.basicConfig(level=logging.INFO, stream=sys.stderr, format='%(asctime)s [%(name)s] %(levelname)s: %(message)s') logger = logging.getLogger(__name__) # This creates an Elasticsearch index for Member model # Elasticsearch index can be treated as table in SQL database Member.init() # TODO: Add exception handling and return 5xx page if needed @app.route('/') def index(): return render_template('index.html') @app.route('/lunch_time') def lunch_time(): # seed should be None if it's not specified or an empty string seed = request.args.get('seed') or None # NOTE: There may be a performance issue if there are millions of members
if __name__ == '__main__': from nagels import Nagels from members import Member verbindingskrachten = { 'Alfa': 1.57, 'AlfaTrek': 0, 'Rad': 1.57, 'RadTrek': 0 } member_staal = Member(materiaal='staal', dikte=5, zijde='kop', treksterkte=235, hechtlengte=4) member_hout = Member(materiaal='hout', dikte=71, zijde='kop', hout_type='osb', ro=320, kmod=0.9, fc=2.2, hechtlengte=56) member_hout_2 = Member(materiaal='hout', dikte=71, zijde='punt', hout_type='loofhout', ro=320,
def list_members(): return render_template('list_members.html', members=Member.all())