Beispiel #1
0
    def get(self):
        # Checks for active Google account session for app auth
        user = users.get_current_user()
        if user:
            logging.debug('User found, object instance: %s', user)
            user_id = users.get_current_user().user_id()
            logging.debug('User id: %s', user_id)

            # Checks for Quant session
            session = SessionData.query(SessionData.user == user_id).get()
            # If not, init a session
            if not session:
                session = SessionData(
                    user=user_id,
                    email=user.nickname(),
                )
                session.put()
                # logging.debug(session.available)
            # logging.debug(session)
            ## Code to render home page
            template = JINJA_ENVIRONMENT.get_template('upload.html')
            template_vars = {'upload_form_url': '/process'}
            self.response.out.write(template.render(template_vars))
        else:
            logging.debug("No user -> need login")
            self.redirect(users.create_login_url(self.request.url))
Beispiel #2
0
    def get(self):
        logging.debug("NDB debug")
        user = users.get_current_user()
        if user:
            logging.debug('User found, object instance: %s', user)
            user_id = users.get_current_user().user_id()
            logging.debug('User id: %s', user_id)
            logging.debug(user.user_id())
            logging.debug(user.nickname())

            # Checks for Quant session
            session = SessionData.query(SessionData.user == user_id).get()
            # If not, init a session
            if not session:
                logging.debug("No session")
                session = SessionData(user=user_id, email=user.nickname())
                session.put()
                session_key = session.put()
                # mode = QuantModeModel(parent=session_key)
                mode = QuantModeModel.get_or_insert("DEFAULT")
                mode_key = mode.put()
                session.currentMode = mode_key
                session.put()

            modes = QuantModeModel.query(ancestor=session.key)

            #key_to_delete = ndb.Key(QuantModeModel, kkk_id)

            #            for m in list_of_modes:
            # logging.debug("Mode key id: %s", m.key.id());
            # logging.debug("Mode title: %s", m.title);
            # logging.debug("Mode key: %s", m.key.urlsafe());
            #               logging.debug(m.key.urlsafe)

            # query = QuantModeModel.query()
            # getKey = query.get()
            # logging.debug(getKey)
            # logging.debug(getKey.key.urlsafe())

            # mode = QuantModeModel.query(QuantModeModel.qtarget=='Co').get()
            # logging.debug(mode.key.id())

            # ludo = QuantModeModel.get_by_id("Cameron")

            # user_id = users.get_current_user().user_id()
            # session = SessionData.query(SessionData.user == user_id).get()
            # user_data_key = session.key
            # #get ID of entity Key
            # qmode_key = ndb.Key(QuantModeModel, 'cameron', parent=session.key)
            # qmode = qmode_key.get()

            # qmode_key = ndb.Key(QuantModeModel, 'Cameron')
            # key = Key(QuantModeModel, 'Cameron').get()
            # logging.debug(qmode)

            self.response.out.write('Done')
        else:
            logging.info("No user -> need login")
            self.redirect(users.create_login_url(self.request.url))
Beispiel #3
0
    def save_mode(self, qname, qdesc, qtarget, qlambda, a, b, inventory,
                  input_id):
        #id will be greater than zero when EDIT action is triggered.
        user_id = users.get_current_user().user_id()
        if input_id > 0:
            session = SessionData.query(SessionData.user == user_id).get()
            user_data_key = session.key
            #get ID of entity Key
            qmode = ndb.Key(QuantModeModel, input_id, parent=session.key).get()

            # qmode = QuantModeModel.get_by_id(id)
            # qmode_key = ndb.Key(urlsafe=id)
            # qmode_key = ndb.Key('QuantModeModel', id)
            # qmode = qmode_key.get()
            # logging.debug(qmode)

#                        qmode = ndb.Key(urlsafe=qmode_key).get()

# member2 = QuantModeModel.get_by_id(id)
# qmode_key = ndb.Key(QuantModeModel, id)
# qmode = qmode_key.get()
        else:
            #			company = CompanyModel(id='RedRock',name='RedRock Enterprise')
            # company = CompanyModel(name='RedRock Enterprise')
            # company.put()

            # Get session data instance
            user = users.get_current_user()
            logging.debug(user_id)
            session = SessionData.query(SessionData.user == user_id).get()
            user_data_key = session.key

            # Get session data instance key
            qmode = QuantModeModel(title=qname, parent=session.key)

        qmode.qlambda = qlambda
        qmode.qtarget = qtarget
        qmode.fwhma = a
        qmode.fwhmb = b
        qmode.inventory = inventory
        qmode.description = qdesc
        qmode.title = qname

        #		qmode.user_name = users.get_current_user().email()
        key = qmode.put()

        session.currentMode = key
        session.put()
Beispiel #4
0
    def get(self):
        user = users.get_current_user()
        if user:
            user_id = users.get_current_user().user_id()
            session = SessionData.query(SessionData.user == user_id).get()
            # Checks for Quant session
            # If not, init a session
            if not session:
                session = SessionData(
                    user=user_id,
                    email=user.nickname(),
                )

                session_key = session.put()
                mode = QuantModeModel(parent=session_key)
                mode_key = mode.put()
                session.currentMode = mode_key
                session.put()

            # Get the current Mode
            mode = session.currentMode.get()

            logging.debug(mode.selected)
            logging.debug(mode.available)

            template = JINJA_ENVIRONMENT.get_template('phase.html')
            template_vars = {
                'availablephaselist': mode.available,
                'selectedphaselist': mode.selected,
                'mode': mode
            }
            self.response.out.write(template.render(template_vars))
        else:
            logging.info("No user -> need login")
            self.redirect(users.create_login_url(self.request.url))
Beispiel #5
0
    def get(self):
        logging.debug("Calibration")
        user = users.get_current_user()
        if user:
            user_id = users.get_current_user().user_id()
            session = SessionData.query(SessionData.user == user_id).get()
            if not session:
                # a = -0.001348
                # b =  0.352021
                session = SessionData(user=user_id, email=user.nickname())
                session_key = session.put()
                mode = QuantModeModel(parent=session_key)
                mode_key = mode.put()
                session.currentMode = mode_key
                session.put()

            # Get the current Mode
            mode = session.currentMode.get()
            # logging.debug(mode)
            template = JINJA_ENVIRONMENT.get_template('calibration.html')
            template_vars = {
                'lambda': mode.qlambda,
                'target': mode.qtarget,
                'a': mode.fwhma,
                'b': mode.fwhmb
            }
            self.response.out.write(template.render(template_vars))
        else:
            logging.info("No user -> need login")
            self.redirect(users.create_login_url(self.request.url))
Beispiel #6
0
    def get(self):
        logging.debug("Modes")
        user = users.get_current_user()
        if user:
            user_id = users.get_current_user().user_id()
            session = SessionData.query(SessionData.user == user_id).get()
            logging.debug("session")
            if not session:
                session = SessionData(user=user_id, email=user.nickname())
                session_key = session.put()
                mode = QuantModeModel(parent=session_key)
                mode_key = mode.put()
                session.currentMode = mode_key
                session.put()

            # list_of_modes = ndb.get_multi(session.modes)
            # logging.debug(list_of_modes)
            # for k in list_of_modes:
            #     logging.debug(k.title)
            # logging.debug(len(list_of_modes))
            # for m in list_of_modes:
            #     logging.debug(m)

            mode = QuantMode()
            list = mode.list_mode()

            template_vars = {'modes': mode.list_mode()}
            template = JINJA_ENVIRONMENT.get_template('modes.html')
            self.response.out.write(template.render(template_vars))
        else:
            logging.info("No user -> need login")
            self.redirect(users.create_login_url(self.request.url))
Beispiel #7
0
 def get(self):
     obj_key = ndb.Key(urlsafe=self.request.get('img_id'))
     ludo = obj_key.get()
     user_id = users.get_current_user().user_id()
     ludo = SessionData.query(SessionData.user == user_id).get()
     if ludo.avatar:
         self.response.headers['Content-Type'] = 'image/png'
         self.response.out.write(ludo.avatar)
     else:
         self.response.out.write('No image')
Beispiel #8
0
    def post(self):
        #get all input values
        user_id = users.get_current_user().user_id()
        session = SessionData.query(SessionData.user == user_id).get()
        active_mode = self.request.get('mode').strip()
        logging.debug(active_mode)

        qmode_k = ndb.Key('QuantModeModel',
                          int(active_mode),
                          parent=session.key)
        logging.debug(qmode_k)
        session.currentMode = qmode_k
        session.put()
        self.redirect('/')
Beispiel #9
0
    def list_mode(self):
        user = users.get_current_user()
        user_id = users.get_current_user().user_id()
        logging.debug(user_id)
        session = SessionData.query(SessionData.user == user_id).get()
        logging.debug("List Mode")
        logging.debug(session)

        user_data_key = session.key

        mode_query = QuantModeModel.query()
        logging.debug(mode_query)
        mode_query = QuantModeModel.query(ancestor=session.key)
        return mode_query
Beispiel #10
0
 def get(self):
     user_id = users.get_current_user().user_id()
     logging.debug(user_id)
     session = SessionData.query(SessionData.user == user_id).get()
     logging.debug(session.key)
     angle, diff, bgpoly, calcdiff = dynamic_png(session.key)
     #        json_obj = {'angle': angle.tolist(), 'diff': diff.tolist(), 'bgpoly': bgpoly.tolist()}
     json_obj = {
         "filename": session.sampleFilename,
         "angle": angle.tolist(),
         "diff": diff.tolist(),
         "bgpoly": bgpoly.tolist(),
         "calcdiff": calcdiff.tolist(),
         "phases": session.results
     }
     # logging.debug(json.dumps(json_obj))
     self.response.out.write(json.dumps(json_obj))
Beispiel #11
0
    def post(self):
        logging.debug("Post args: %s", self.request.arguments())
        selectedlist = self.request.get_all('selectedphase')
        availlist = self.request.get_all('availablephase')
        logging.debug('Phaselist selected retrieved: %s', selectedlist)
        # logging.debug('Phaselist available retrieved: %s', availlist)
        user_id = users.get_current_user().user_id()
        session = SessionData.query(SessionData.user == user_id).get()
        mode = session.currentMode.get()

        selectedlist.sort()
        availlist.sort()

        mode.selected = selectedlist
        mode.available = availlist
        mode.put()
        # self.redirect('/plot')
        self.redirect('/')
Beispiel #12
0
    def get(self):
        # Needs to be refactored server vs client csv generation - currently taking the user session results and dumping
        user = users.get_current_user()
        user_id = users.get_current_user().user_id()
        session = SessionData.query(SessionData.user == user_id).get()

        url_string = self.request.get('key')
        # logging.debug(url_string)
        # logging.debug("Hello CSV")
        # user_key = ndb.Key(urlsafe=url_string)
        # user = user_key.get()
        logging.debug(session.results)
        self.response.headers['Content-Type'] = 'text/csv'
        self.response.headers[
            'Content-Disposition'] = 'attachment; filename={}.csv'.format(
                session.sampleFilename)
        writer = csv.writer(self.response.out)
        writer.writerow(['Mineral', 'AMCSD', 'Mass %'])
        writer.writerows(session.results)
Beispiel #13
0
    def get(self):
        logging.debug("Edit Modes")
        user = users.get_current_user()
        if user:
            user_id = users.get_current_user().user_id()
            session = SessionData.query(SessionData.user == user_id).get()
            user_data_key = session.key
            # Key of QuantModeModel entity
            logging.debug(self.request.get('id'))
            key_id = self.request.get('id')

            mode = ndb.Key('QuantModeModel', int(key_id),
                           parent=session.key).get()
            # mode = ndb.Key(urlsafe=key_str).get()
            logging.debug(mode)
            template_values = {'mode': mode, 'key': key_id}
            template = JINJA_ENVIRONMENT.get_template('modesEdit.html')
            self.response.out.write(template.render(template_values))
        else:
            self.redirect(users.create_login_url(self.request.uri))
Beispiel #14
0
    def delete_mode(self, mode_ids):
        logging.debug("Delete Mode")
        if len(mode_ids) > 0:
            user_id = users.get_current_user().user_id()
            session = SessionData.query(SessionData.user == user_id).get()

            for mode_id in mode_ids:
                logging.debug(mode_id)
                # qmode_k = ndb.Key(urlsafe=mode_key)
                qmode_k = ndb.Key('QuantModeModel',
                                  int(mode_id),
                                  parent=session.key)
                logging.debug(qmode_k)
                # if qmode_k in session.modes:
                #         idx = session.modes.index(qmode_k)
                #         del session.modes[idx]
                #         session.put()

                qmode = qmode_k.get()
                logging.debug(qmode)
                qmode_k.delete()
Beispiel #15
0
    def post(self):
        user_id = users.get_current_user().user_id()
        session = SessionData.query(SessionData.user == user_id).get()
        mylambda = self.request.get('lambda')
        mytarget = self.request.get('target')
        a = self.request.get('fwhma')
        b = self.request.get('fwhmb')

        logging.debug('Lambda retrieved: %s', mylambda)
        logging.debug('Target retrieved: %s', mytarget)

        mode = session.currentMode.get()

        mode.qtarget = self.request.get('target')
        if mylambda:
            mode.qlambda = float(mylambda)
        if a:
            mode.fwhma = float(a)
        if b:
            mode.fwhmb = float(b)
        mode.put()
        # self.redirect('/plot')
        self.redirect('/')
Beispiel #16
0
    def post(self):
        logging.debug("Loading File...")
        user = users.get_current_user()
        if user:
            logging.debug('User found, object instance: %s', user)
            user_id = users.get_current_user().user_id()
            logging.debug('User id: %s', user_id)
            logging.debug(user.user_id())
            logging.debug(user.nickname())

            # Checks for Quant session
            session = SessionData.query(SessionData.user == user_id).get()
            # If not, init a session
            if not session:
                session = SessionData(user=user_id, email=user.nickname())
                session.put()
                session_key = session.put()
                # mode = QuantModeModel(parent=session_key)
                mode = QuantModeModel.get_or_insert("DEFAULT")
                mode_key = mode.put()
                session.currentMode = mode_key
                session.put()

            session.sampleBlob = self.request.get('file')
            session.sampleFilename = self.request.params["file"].filename
            session_data_key = session.put()
            logging.debug(session.sampleFilename)
            logging.debug(session_data_key)

            # query modes
            modes = QuantModeModel.query(ancestor=session.key)

            for m in modes:
                logging.debug(m.title)

            # Generate image, returns results
            angle, diff, bgpoly, calcdiff = dynamic_png(session.key)

            mode = session.currentMode.get()
            logging.debug(mode.title)

            csv = session_data_key.urlsafe()
            template = JINJA_ENVIRONMENT.get_template('chart.html')
            template_vars = {
                'phaselist': session.results,
                'angle': angle.tolist(),
                'diff': diff.tolist(),
                'bgpoly': bgpoly.tolist(),
                'sum': calcdiff.tolist(),
                'url_text': csv,
                'key': session_data_key.urlsafe(),
                'samplename': session.sampleFilename,
                'mode': mode
            }
            self.response.out.write(template.render(template_vars))
        else:
            logging.debug("No user -> need login")
            self.redirect(users.create_login_url('/'))
Beispiel #17
0
    def post(self):
        logging.debug("Create Modes")
        #get all input values
        qtarget = self.request.get('target').strip()
        qlambda = self.request.get('lambda').strip()
        fwhma = self.request.get('fwhma').strip()
        fwhmb = self.request.get('fwhmb').strip()
        title = self.request.get('modeTitle').strip()
        inventory = self.request.get('inventory').strip()
        description = self.request.get('modeDesc').strip()

        # Populate the phaselist according to the inventory choice
        # Read in the file
        jump = 1
        if inventory == "cement":
            phaselistname = 'difdata_cement_inventory.csv'
        elif inventory == "pigment":
            phaselistname = 'difdata_pigment_inventory.csv'
        elif inventory == "rockforming":
            phaselistname = 'difdata-rockforming_inventory.csv'
        elif inventory == "chemin":
            phaselistname = 'difdata_CheMin_inventory.csv'
        else:
            logging.debug("Can't find inventory")

        phaselist = open(phaselistname, 'r').readlines()[jump:]

        phaselist.sort()
        logging.debug(phaselist)

        user_id = users.get_current_user().user_id()
        session = SessionData.query(SessionData.user == user_id).get()

        # Mode creation: last parameter = 0
        # mode = QuantMode()
        # mode.save_mode(title ,qtarget, float(qlambda), float(fwhma), float(fwhmb), inventory, phaselist, 0)

        # Create mode
        qmode = QuantModeModel(title=title, parent=session.key)

        qmode.qlambda = float(qlambda)
        qmode.qtarget = qtarget
        qmode.fwhma = float(fwhma)
        qmode.fwhmb = float(fwhmb)
        qmode.inventory = inventory
        qmode.description = description
        qmode.selected = phaselist
        qmode.available = []

        key = qmode.put()

        session.currentMode = key
        session.put()

        # mode = QuantModeModel(title=title,
        #                       qlambda=float(qlambda),
        #                       qtarget=qtarget,
        #                       fwhma=float(fwhma),
        #                       fwhmb=float(fwhmb))
        # key = mode.put()

        # user_id = users.get_current_user().user_id()
        # session = SessionData.query(SessionData.user == user_id).get()

        # session.modes.append(key)
        # session.put()

        # list_of_modes = ndb.get_multi(session.modes)
        # for k in list_of_modes:
        #     logging.debug(k)

        # logging.debug(session)

        self.redirect('/modes')