def upload_record(): """ Upload a new Radiology Record """ form = RecordForm(request.form) # Populate the Form patients = selectPersonsWhoArePatients() patientChoices = personChoicesForSelectField(patients) doctors = selectPersonsWhoAreDoctors() doctorChoices = personChoicesForSelectField(doctors) radiologists = selectPersonsWhoAreRadiologists() radiologistChoices = personChoicesForSelectField(radiologists) form.patient_id.choices = patientChoices form.doctor_id.choices = doctorChoices form.radiologist_id.choices = radiologistChoices if form.validate_on_submit(): # Create the Record record = models.Record() form.populate_obj(record) db.session.add(record) db.session.commit() # Create the images images = request.files.getlist("images") if images: for img in images: # Create Images file_name = str(uuid.uuid4()) + secure_filename(img.filename) image_file = os.path.join(app.config['UPLOAD_FOLDER'], file_name) img.save(image_file) thumb_file_name = os.path.splitext(file_name)[0] + ".thumbnail" thumb_file = os.path.splitext(image_file)[0] + ".thumbnail" regular_file_name = os.path.splitext(file_name)[0] + ".regular" regular_file = os.path.splitext(image_file)[0] + ".regular" # Resize resize_image_thumb(img, thumb_file) resize_image_regular(img, regular_file) image = models.Image( record_id=record.record_id, thumbnail=thumb_file_name.encode('utf-8'), regular_size=regular_file_name.encode('utf-8'), full_size=file_name.encode('utf-8')) db.session.add(image) db.session.commit() flash(u'Record {} has been saved'.format(record.record_id)) return redirect(url_for('list_records')) return render_template('upload_record.html', title='Upload a Record', form=form)
def identify(img): print "identify" render_data = {"worker_id": request.args.get("workerId"), "assignment_id": request.args.get("assignmentId"), "amazon_host": AMAZON_HOST, "hit_id": request.args.get("hitId")} print render_data if request.method == 'POST': x_locs = json.loads(request.form['x-locs']) y_locs = json.loads(request.form['y-locs']) object_names = json.loads(request.form['obj-names']) comment = json.loads(request.form['comment-input']) #Store all the collected data in the database worker_id = models.Worker.query.filter_by(turker=request.args.get("workerId")).first().id image_id = models.Image.query.filter_by(filename=img).first().id for name,x,y in zip(object_names,x_locs,y_locs): obj = models.Object(image_id=image_id,name=name) db.session.add(obj) db.session.commit() obj_location = models.ObjectLocation(object_id=obj.id,worker_id=worker_id,x_loc=x,y_loc=y) db.session.add(obj_location) db.session.commit() resp = make_response(render_template('submit.html',name=render_data)) resp.headers['x-frame-options'] = 'this_can_be_anything' return resp filename = '../static/' + img + '.png' #Read objects that have already been identified from the database worker = models.Worker.query.filter_by(turker=request.args.get("workerId")).first() if worker is None and render_data["worker_id"] != 'None': db.session.add(models.Worker(turker=request.args.get("workerId"))) db.session.commit() image = models.Image.query.filter_by(filename=img).first() if image is None: db.session.add(models.Image(filename=img)) db.session.commit() image_id = models.Image.query.filter_by(filename=img).first().id objects = models.Object.query.filter_by(image_id=image_id).order_by(models.Object.name).all() #Read object locations for these objects object_locations = models.ObjectLocation.query.filter((models.ObjectLocation.object_id.in_([x.id for x in objects]))).all() #Make this data easy to use objects = {x.id:x.name for x in objects} object_locations = {x.object_id:(x.x_loc,x.y_loc) for x in object_locations} #ASSUMES THAT EACH OBJECT IS MARKED BY EXACTLY 1 WORKER print "end identify" #The following code segment can be used to check if the turker has accepted the task yet if request.args.get("assignmentId") == "ASSIGNMENT_ID_NOT_AVAILABLE": #Our worker hasn't accepted the HIT (task) yet # resp = make_response(render_template('identify.html',name=render_data,filename=filename,ht=384,wd=512,accepted=False,objects=objects,locs=object_locations,img=img)) return render_template('identify.html',name=render_data,filename=filename,ht=384,wd=512,accepted=False,objects=objects,locs=object_locations,img=img) else: #Our worker accepted the task # resp = make_response(render_template('identify.html',name=render_data,filename=filename,ht=384,wd=512,accepted=True,objects=objects,locs=object_locations,img=img)) return render_template('identify.html',name=render_data,filename=filename,ht=384,wd=512,accepted=True,objects=objects,locs=object_locations,img=img)
def segment(img,objId): print "segment" print "objId: ",objId render_data = {"worker_id": request.args.get("workerId"), "assignment_id": request.args.get("assignmentId"), "amazon_host": AMAZON_HOST, "hit_id": request.args.get("hitId")} print render_data print "img: ",img filename = '../../../static/' + img + '.png' print filename #Read objects that have already been identified from the database worker = models.Worker.query.filter_by(turker=request.args.get("workerId")).first() if worker is None and render_data["worker_id"] != 'None': db.session.add(models.Worker(turker=request.args.get("workerId"))) db.session.commit() # print "img: "+img image = models.Image.query.filter_by(filename=img).first() if image is None: db.session.add(models.Image(filename=img)) db.session.commit() image_id = models.Image.query.filter_by(filename=img).first().id objects = models.Object.query.filter_by(image_id=image_id).order_by(models.Object.name).all() #Read object locations for these objects object_locations = models.ObjectLocation.query.filter((models.ObjectLocation.object_id.in_([x.id for x in objects]))).all() print "objects: ",objects print "object_locations: ",object_locations #Make this data easy to use objects = {x.id:x.name for x in objects} object_locations = {x.object_id:(x.x_loc,x.y_loc) for x in object_locations} #ASSUMES THAT EACH OBJECT IS MARKED BY EXACTLY 1 WORKER print objects print object_locations # randkey=objects.keys()[randint(0,len(objects)-1)] # obj = objects[randkey] # objloc = object_locations[randkey] obj = objects[objId] objloc = object_locations[objId] print "objloc: ", objloc print "obj: " , obj # print "object_id: ",object_id #The following code segment can be used to check if the turker has accepted the task yet if request.args.get("assignmentId") == "ASSIGNMENT_ID_NOT_AVAILABLE": #Our worker hasn't accepted the HIT (task) yet resp = make_response(render_template('page.html',name=render_data,filename=filename,ht=384,wd=512,accepted=False,object=obj,objId=objId,loc=objloc,img=img)) else: #Our worker accepted the task resp = make_response(render_template('page.html',name=render_data,filename=filename,ht=384,wd=512,accepted=True,object=obj,objId=objId,loc=objloc,img=img)) resp.headers['x-frame-options'] = 'this_can_be_anything' print "here" return resp
from app import db, models import datetime ### NEWS IMAGES ### news_images = [] news_images.append( models.Image(image_type='news', alt_text="UPE 2015", image_extension='jpg', image_name='UPE2015')) news_images.append( models.Image(image_type='news', alt_text="Programming Team", image_extension='jpg', image_name='programming_team')) news_images.append( models.Image(image_type='news', alt_text="VWCS", image_extension='jpg', image_name='VWCS')) ### NEWS ### news = [] news.append( models.News( headline='Congratulations 2015 UPE Inductees!', intro='On October 23, 2015 nineteen students were recognized for '
from app import db, models import datetime image_icon = models.Image(image_type='icon', alt_text="XJ's_awesome_selfie", image_extension='png') sideview = models.Sideview( content= "There are many frameworks available for iOS 2D game development such" " as Unity, Corona, SpriteKit, Cocos2D etc... Many people are turned off from" " learning these frameworks because they seem really complicated. The purpose" " of my project to create a couple iOS 2D games using Cocos2D and SpriteKit" " and perform a comparison of these two frameworks. The reason for a comparison" " between Cocos2D and SpriteKit is that most game on the App Store are created" " using Cocos2D, and on the other hand, SpriteKit is Apple's 2D game development" " framework that was based off Cocos2D. It would be interesting to see the pros" " and cons of each framework side by side. For my first iOS game - Drop Blocks!" " visit this link: https://bitly.com/a/bitlinks - I used Cocos2D, it is a very" " simple game where blocks will move back and forth on the top of the screen" " and the user will tap the screen to drop the blocks. The user will be able" " to gain points and erase blocks if the blocks are matched with 3 or more same" " color blocks horizontally or vertically.", title='2D Game Development', category='Senior Project', active=1, image=image_icon) news = models.News( headline='Congratulations 2014 UPE Inductees!', intro='On Friday, April 4 2014, eleven graduate students and'
def populate(): """ Populate database with test data""" po1 = models.Officer(last_name='Tinkle', first_name='Ivana', race='BLACK', gender='F', employment_date=datetime(2000, 4, 4, 1, 1, 1), birth_year=1970, pd_id=1) po2 = models.Officer(last_name='Jass', first_name='Hugh', race='WHITE', gender='M', birth_year=1950, pd_id=1, employment_date=datetime(1996, 4, 4, 1, 1, 1)) po3 = models.Officer(last_name='Butz', first_name='Seymour', race='WHITE', gender='F', birth_year=1950, pd_id=1, employment_date=datetime(1983, 4, 4, 1, 1, 1)) po4 = models.Officer(last_name='Cuddleme', first_name='Haywood', middle_initial='U', race='HISPANIC', gender='F', birth_year=1950, pd_id=1, employment_date=datetime(2014, 4, 4, 1, 1, 1)) test_officers = [po1, po2, po3, po4] db.session.add_all(test_officers) db.session.commit() po1 = models.Officer.query.get(1) po2 = models.Officer.query.get(2) po3 = models.Officer.query.get(3) po4 = models.Officer.query.get(4) star1 = models.Assignment(star_no=1234, rank='COMMANDER', officer=po1) star2 = models.Assignment(star_no=5678, rank='PO', officer=po2) star3 = models.Assignment(star_no=9012, rank='CHIEF', officer=po3) star4 = models.Assignment(star_no=3456, rank='LIEUTENANT', officer=po4) test_assignments = [star1, star2, star3, star4] db.session.add_all(test_assignments) db.session.commit() image1 = models.Image(filepath='static/images/test_cop1.png') image2 = models.Image(filepath='static/images/test_cop2.png') image3 = models.Image(filepath='static/images/test_cop3.png') image4 = models.Image(filepath='static/images/test_cop4.png') test_images = [image1, image2, image3, image4] db.session.add_all(test_images) db.session.commit() face1 = models.Face(officer_id=1, img_id=1) face2 = models.Face(officer_id=2, img_id=2) face3 = models.Face(officer_id=3, img_id=3) face4 = models.Face(officer_id=4, img_id=4) test_faces = [face1, face2, face3, face4] db.session.add_all(test_faces) db.session.commit()
def approval(): form = ApprovalForm() if request.method == 'POST': if form.validate(): #Add any images to S3_Bucket s3 = boto3.resource('s3') """ if image_URI_list[len(image_URI_list)-1] == None or image_URI_list[len(image_URI_list)-1] == '': image_URI_list = image_URI_list[:-1] print print print("FOUND BLANK IMAGE") print("length of list is..") print(len(image_URI_list)) """ s3_image_list = [] files = request.files.getlist('files[]') if files: for f in files: if (f.content_type == 'image/png'): base64_URI = f.stream s3_filename = uuid4( ).hex + '.png' #Generate random filename s3.Bucket(S3_BUCKET).put_object( Key=s3_filename, Body=base64_URI, ContentType='image/png', ACL='public-read') i = models.Image(file_name=s3_filename, s3_bucket=S3_BUCKET, approval_date=datetime.now()) s3_image_list.append(i) """ if form.approval_type.data == 'Recon': r = Order.query.filter_by(invoice_num=form.invoice_num.data).first() for s3_image in s3_image_list: r.images.append(s3_image) r.approval_employee_code = form.approval_employee_code.data r.tracking_number = form.tracking_number.data if form.have_repair.data == 'y': r.have_repair = True r.repair_comments = form.repair_comments.data else: r.have_repair = False if form.stickered_engraved.data == 'y': r.stickered_engraved = True else: r.stickered_engraved = False r.light_approved = form.light_approved.data if form.light_approved.data != 'Yes': r.approval_comments = form.approval_comments.data r.approval_type = 'Recon' r.notes = form.notes.data r.approval_date = datetime.now() r.status = 'Approved' else: """ print("SWAP: " + str(form.swap_out.data)) if form.light_approved.data != 'Yes': comm = form.approval_comments.data else: comm = '' r = models.Order( invoice_num=form.invoice_num.data, tracking_number=form.tracking_number.data, approval_employee_code=form.approval_employee_code.data, light_approved=form.light_approved.data, notes=form.notes.data, approval_comments=comm, approval_type=form.approval_type.data, light_type=form.light_type.data, interchange=form.interchange.data, approval_date=datetime.now(), tested_bare=form.tested_bare.data, repair_comments=form.repair_comments.data, have_repair=form.have_repair.data, swap_out=form.swap_out.data, bake_wash=form.bake_wash.data, light_noted=form.light_noted.data, status='Approved') for s3_image in s3_image_list: r.images.append(s3_image) db.session.add(r) db.session.commit() flash('Record saved.') return redirect("approval") else: return json.dumps(form.errors) return render_template('approval.html', form=form)