Ejemplo n.º 1
0
def main(argv = None):
	udata = UserData()

	#populate user data
	if udata.populate_data() == False:
		print 'Unable to populate user data, please check the credentials.\n'
		return

	display user data
	print 'User data populated\n'

	prompt = raw_input('Print user data? (y\\n)?')
	
	if (prompt == 'y'):
		for user in udata.users:
			print user
	
	#login to email
	sender = GMailSender()
	while sender.login() == False:
		pass

	
	print 'Enter email subject:'
	subject = stdin.readline()
Ejemplo n.º 2
0
 def __init__(self):
     super().__init__("survey")
     self.__course = Course()
     self.__enrol = enrol_Data()
     self.__user = UserData()
     # set up the join search columns
     self.clear()
Ejemplo n.º 3
0
def placeOrder():
    form = AddressForm(request.form)
    if form.errors:
        return jsonify(status='fail', errors=form.errors)

    for shippingMethod in g.shippingMethods:
        if shippingMethod.name == request.form["shipping"]:
            g.cart.updateShipping(shippingMethod.price)
    userData = UserData(phone=form.phone.data,
                        email=form.email.data,
                        region=form.region.data,
                        city=form.city.data,
                        address=form.address.data)
    userData.userId = g.user.id
    db.session.add(userData)
    db.session.commit()

    order = Order(g.cart.getTotal(), g.user.id, userData.id)
    db.session.add(order)
    db.session.commit()

    # Now add the products in the cart.
    for product_id in g.cart.get_products_ids():
        db.session.add(ProductsInOrder(product_id,
                                       order.id,
                                       g.cart.get_quantity_by_id(product_id)))
    db.session.commit()

    cart = []
    for item in g.cart.items:
        cart.append({
            'quantity': g.cart.items[item]['quantity'],
            'name': Product.query.get(item).name,
            'price': g.cart.items[item]['price']
        })

    sendMail(subject='Factura',
             sender=app.config['ADMINS'][0],
             recipients=[form.email.data, app.config['ADMINS'][0]],
             messageBody='----',
             messageHtmlBody=render_template('bill.html',
                                             cart=cart,
                                             name=g.user.name,
                                             total=g.cart.getTotal(),
                                             phone=form.phone.data,
                                             region=form.region.data,
                                             city=form.city.data,
                                             address=form.address.data,
                                             shipping=request.form['shipping'],
                                             shippingCost=ShippingMethods.query.filter_by(
                                                 name=request.form['shipping']).first().price)
    )


    # Reset the cart.
    session["cart"] = {}

    return jsonify(status="ok")
Ejemplo n.º 4
0
def load_user(userid):
    usr = UserData()
    if not userid:
        raise TypeError("Please provide your user id.")
    try:
        role = usr.findById(int(userid))[2]
    except Exception as e:
        raise TypeError("Wrong username/password, please try again.")
    # initialise the class by the role
    if role == 'admin':
        return Admin(userid)
    elif role == 'student':
        return Student(userid)
    elif role in ["guest", "unguest"]:
        return Guest(userid)
    elif role == 'staff':
        return Staff(userid)
Ejemplo n.º 5
0
def user_data():
    """ Creates test user data """
    return UserData(
        profileImage="",
        name="Yuan Gao",
        handle="meseta",
        id=GH_TEST_ID,
        accessToken=GH_TEST_TOKEN,
    ).dict()
Ejemplo n.º 6
0
def testing_user_data():
    user_id = "test_" + "".join(
        [random.choice(string.ascii_letters) for _ in range(10)])
    return UserData(
        profileImage="",
        name="Test User",
        handle="test_user",
        id=user_id,
        accessToken="",
    )
Ejemplo n.º 7
0
def register():
    error = None
    if request.method == "POST":
        if request.form['pw'] == request.form['re_pw']:
            try:
                UserData().register(request.form['id'], request.form['pw'])
                return render_template(
                    "msg.html",
                    msg_suc_l=[
                        'Successful Register',
                        "Wait for admin to approve your request.",
                        url_for('index'), "Return to Home Page"
                    ])
            except Exception as e:
                # extract the mesage of error
                error = format(e)
        else:
            error = "Password provided is not same."

    # Render pront for register
    return render_template("register.html", msg_err=error)
Ejemplo n.º 8
0
def dashboard():

    # route by the current user type
    c = Course()
    # get the survey instance
    s = Survey()

    # muti type of user respond
    if current_user.is_student():
        return render_template('dash/student.html',\
                survey_l = s.get_survey_by_user(current_user.uid))
    if current_user.is_staff():
        return render_template('dash/staff.html',\
                survey_l = s.get_survey_by_user(current_user.uid))
    if current_user.is_admin():
        # get all the ongoning survey and all the courses
        return render_template('dash/admin.html',survey_l = s.get_survey(),\
                course_l= c.get_course(),guest_l = UserData().show_unguest(),\
                enrol_l = EnrolRequest().get_requests())
    if current_user.is_guest():
        return render_template('dash/guest.html',\
                    survey_l = s.get_survey_by_user(current_user.uid),\
                    course_l= c.get_course())
Ejemplo n.º 9
0
class Survey(SqlUtil):
    """docstring for survey."""
    def __init__(self):
        super().__init__("survey")
        self.__course = Course()
        self.__enrol = enrol_Data()
        self.__user = UserData()
        # set up the join search columns
        self.clear()

    def clear(self,join = False, col = False):
        super().clear(join = True, col= True)
        if not col and not join:
            # set up the default join searching order
            self.with_table("course","course_id","id")\
                .col_name("id").col_name(["course_code","course_year"],"course")\
                .col_name(["Q_id","start_time","end_time","status"])
        return self

    def create_survey(self,course_code,course_year,Q_id,start_time,end_time):
        # error handling
        if not Q_id:
            raise TypeError("You must select at least one question.")
        if type(Q_id)!= list:
            raise TypeError("Question id must bu a list.")
        # getthing this course's id
        this_course = self.__course.get_course(course_code,course_year)
        self.insert("course_id",this_course[0])\
                        .insert("Q_id","&&".join(Q_id))\
                        .insert("start_time",start_time)\
                        .insert("end_time",end_time).save()
        this_survey = self.find(["course_id","Q_id","start_time","end_time"],\
                        [this_course[0],"&&".join(Q_id),start_time,end_time])\
                        .sort_by("survey.id",False).one()

        return this_survey[0]
    def get_survey(self,course_name= None,course_year = None):
        if not course_name and not course_year:
            # return all the ongoning survey
            return self.all()

        # provided course info
        this_course = self.__course.get_course(course_name, course_year)
        # search all the survey provided by this course
        # join search and select all all the information
        # order by id, course_code, course_year, qid, start_time,end_time,status
        this_sur = self.find(["survey.course_id"],[this_course[0]]).all()
        return this_sur


    # for update the information of a survey
    def update_survey(self, survey_id, Q_id, start_time = None, end_time = None):
        # get the survey by id
        self.id_filter(survey_id)

        # generate a new list of question id, and update that
        self.update("Q_id","&&".join(Q_id))

        # if it has satrt time, and end_time update that
        if start_time:
            self.update("start_time", start_time)
        if end_time:
            self.update("end_time", end_time)

        # push the changes to database
        return self.save()

    def get_survey_by_user(self, user_id):
        this_courses =self.__enrol.clear(True,True).findById(user_id)
        # getting the class of the user
        this_user = self.__user.findById(user_id)

        print(this_courses)

        if not this_courses:
            # thie user dont enrolled to any courses
            return []
        survey_list =[]

        # id to filte the survey_list
        filter_arr =[]
        # status filter
        if this_user[2] == "staff":
            # only can reach the status echo to 1
            self.findIn("status", ["1","2","3"], sign = "=")
        elif this_user[2]== "student":
            # only can reach the status echo to 2 and 3
            self.findIn("status", ["2","3"], sign = "=")

            # find the which survey this user has submitted

            filter_arr =SqlUtil("respond").find("user_id",this_user[0]).all()
            # get filter_arr only has id of submitted survey
            filter_arr = [this[1] for this in filter_arr]

        # get the ongoning survey by course
        survey_list =self.findIn("course_id", [this[1] for this in this_courses]).all()



        return survey_list

    def is_premitted(self, survey_id, user_id):
        this_sur = self.id_filter(survey_id).one()
        his_enrol = self.__enrol.find(["user_id","course_code","course_year"]\
                        ,[user_id,this_sur[1],this_sur[2]]).one()
        if his_enrol:
            return True
        return False


    # status : 0 = just created, 1 = ask for review
    # status : 2 = student access, close = student can access the data
    def __change_status(self,sid, status):
        # post survey to related staff, stage = review
        self.id_filter(sid).update("status",status).save()
        return self

    def post(self,sid):
        # set the status to 1
        return self.__change_status(sid, 1)


    def review(self, sid):
        # post survey to related student, stage = review
        return self.__change_status(sid, 2)

    def close(self, sid):
        # post survey to finished, stage = closed
        return self.__change_status(sid, 3)


    def delete_survey(self,sid):
        if type(sid)!= int:
            raise TypeError("input id must be int")
        self.id_filter(sid).delete()
        return self

    def id_filter(self, sid):
        return self.find("survey.id",sid)

    def get_qids(self, sid):
        # getting back an array of question id
        qids = self.id_filter(sid).one()[3]
        if qids:
            # prevent the error caused by qids is empty string
            qids = qids.split("&&")
            qids = [int(this_id) for this_id in qids]
        else:
            qids  =[]
        return qids
Ejemplo n.º 10
0
def main():

    parser = get_parser()

    try:
        args = parser.parse_args()
    except:
        sys.exit(0)

    from deid.dicom import get_files
    from logger import bot

    if args.folder is None:
        bot.error("Please provide a folder with dicom files with --input.")
        sys.exit(1)

    dicom_files = get_files(args.folder)
    number_files = len(list(get_files(args.folder)))

    ##### the following includes all steps to go from raw images to predictions
    ##### pickle models are passed as argument to select_text_among_candidates
    ##### and classify_text methods are result of a previously implemented pipeline.
    ##### just for the purpose of clarity the previous code is provided.
    ##### The commented code is the one necessary to get the models trained.

    # Keep a record for the user
    result = {'clean': 0, 'detected': 0, 'skipped': 0, 'total': number_files}

    # For each file, determine if PHI, for now just alert user
    for dicom_file in dicom_files:

        dicom_name = os.path.basename(dicom_file)

        # Try isn't a great approach, but if we log the skipped, we can debug
        try:
            dicom = UserData(dicom_file, verbose=args.verbose)

            # plots preprocessed image
            if not args.detect:
                dicom_save_name = '/data/%s_preprocessed.png' % dicom_name
                dicom.save_preprocessed_image(dicom_save_name)

            # detects objects in preprocessed image
            candidates = dicom.get_text_candidates()
            clean = True

            if candidates is not None:

                if args.verbose:
                    number_candidates = len(candidates['coordinates'])
                    bot.debug("%s has %s text candidates" %
                              (dicom_name, number_candidates))
                # plots objects detected
                # dicom.plot_to_check_save(candidates,
                #                          'Total Objects Detected',
                #                          '/data/lao-detect-check.png')

                # selects objects containing text
                saved_model = '/code/data/linearsvc-hog-fulltrain2-90.pickle'
                maybe_text = dicom.select_text_among_candidates(saved_model)

                # plots objects after text detection
                # dicom.plot_to_check_save(maybe_text,
                #                          'Objects Containing Text Detected',
                #                          '/data/lao-detect-candidates.png')

                # classifies single characters
                saved_model = '/code/data/linearsvc-hog-fulltrain36-90.pickle'
                classified = dicom.classify_text(saved_model)
                if args.verbose:
                    number_text = len(classified['coordinates'])
                    bot.debug("%s has %s classified text" %
                              (dicom_name, number_text))

                if len(classified) > 0:
                    if args.verbose:
                        bot.warning("%s flagged for text content." %
                                    dicom_name)
                    clean = False
                else:
                    bot.info("%s is clean" % dicom_name)

            else:
                bot.info("%s is clean" % dicom_name)

            if clean:
                result['clean'] += 1
            else:
                result['detected'] += 1

            # plots letters after classification
            # dicom.plot_to_check_save(classified,
            #                          'Single Character Recognition',
            #                           '/data/lao-detect-letters.png')

            if not clean and not args.detect:
                dicom.scrape_save('/data/%s_cleaned.png' % dicom_name)

        except:
            bot.error("\nProblem loading %s, skipping" % dicom_name)
            result['skipped'] += 1
        print('============================================================')

    # Final result
    print('\n=======================FINALRESULT==========================')
    print(os.path.basename(args.folder))
    print("DETECTED: %s" % result['detected'])
    print("SKIPPED:  %s" % result['skipped'])
    print("CLEAN:    %s" % result['clean'])
    print("TOTAL:    %s" % result['total'])