def refresh_scores(self, verbose): scores = [] json_file = open(ROOT_PATH + "/data/item_scores.json") json_str = json_file.read() newdata = simplejson.loads(json_str) # Load JSON file as object # Retrieve Proficiency. If new, then save it. for item in newdata: # Store Item in Datastore if item["type"] == "trash": continue if item["type"] == "temp": continue this_taker = QuizTaker.get(item["quiz_taker"]["key"]) this_vendor = Employer.get(item["vendor"]["key"]) this_item = QuizItem.get(item["quiz_item"]["key"]) score = ItemScore( quiz_taker=this_taker, picked_answer=item["picked_answer"], correct_answer=item["correct_answer"], score=item["score"], quiz_item=this_item, vendor=this_vendor, type=item["type"], ) # Add List of Answers scores.append(score) if verbose[0] == "loud": print encode(score) db.put(scores) # save scores
def dump_data(data_type): query = DATA_TYPES[data_type] objects = query.fetch(1000) return encode(objects) try: query = DATA_TYPES[data_type] objects = query.fetch(1000) return encode(objects) except: return "unable to encode objects"
def load_quiz_js(self): JQUERY_VERSION = '1.3.2' DEFAULT_QUIZ_SUBJECT = "Recovery.Gov" try : proficiency_arg = self.request.path.split('/quiz/')[1].replace('%20',' ') this_proficiency = Proficiency.get_by_key_name(proficiency_arg) assert this_proficiency != None self.these_proficiencies = [this_proficiency] except: self.these_proficiencies = [Proficiency.get_by_key_name(DEFAULT_QUIZ_SUBJECT)] proficiency_names = [str(p.name) for p in self.these_proficiencies] session_token = self.get_session_token() template_values = { 'proficiencies': encode(proficiency_names).replace("\n", ""), 'user_token': session_token, 'css': self.get_widget_css().replace('\n','').replace("'",'"'), 'widget_html': self.get_widget_html(), 'widget_subject': self.these_proficiencies[0].key(), 'jquery_version' : JQUERY_VERSION, 'jquery_location': JQUERY_VERSION, 'auto_start': self.get_auto_start() } path = widget_path('pqwidget.js') from utils.random import minify self.response.out.write( minify(template.render(path, template_values)) )
def SubmitContentUrl(self, *args): induce_url = RawItemInduction() #JSON Serialize save_url # Induction: # 1. Perform semantic analysis # 2. Retrieve answer candidates # 3. Attempt to create raw quiz items. return encode(induce_url.get(args))
def GetRawItemsForProficiency(self, *args): this_subject = Proficiency.get_by_key_name(args[0]) # try get_or_insert if Proficiency is key prof_pages = this_subject.pages.fetch(10) raw_items = [] for p in prof_pages: these_items = RawQuizItem.gql("WHERE page = :1 AND moderated = False", p ) # only get unmoderated items items = these_items.fetch(1000) raw_items += items try: return encode(raw_items) # get 10 at a time...todo: lazy rpc-loader. except: return simplejson.dumps([])
def get(self): proficiencies = Proficiency.gql("WHERE status = :1", "public"); proficiencies = proficiencies.fetch(1000) buy_buttons = [] for p in proficiencies: p.checkout_button = checkout.render_quiz_button(self, p.tag(), p.name) buy_buttons.append( { 'tag': p.tag().lower(), 'html' : p.checkout_button}) prof_json = encode(proficiencies) template_values = {'proficiencies' : proficiencies, 'prof_json': prof_json, 'buy_buttons': encode(buy_buttons), 'load': 2000} path = tpl_path(STORE_PATH + 'proficiency.html') self.response.out.write(template.render(path, template_values))
def browser_error(self): DEFAULT_QUIZ_SUBJECT = "Recovery.Gov" if not Debug(): self.set_expire_header() try : proficiency_arg = self.request.path.split('/quiz/')[1].replace('%20',' ') this_proficiency = Proficiency.get_by_key_name(proficiency_arg) assert this_proficiency != None self.these_proficiencies = [this_proficiency] except: self.these_proficiencies = [Proficiency.get_by_key_name(DEFAULT_QUIZ_SUBJECT)] proficiency_names = [str(p.name) for p in self.these_proficiencies] session_token = self.get_session_token() template_values = { 'quiz_subject': encode(proficiency_names[0]).replace("\n", "") } path = widget_path('error.js') from utils.random import minify self.response.out.write( minify(template.render(path, template_values)) )
def add_auto_pledge(self, *args): if not args: return "Specify A Business Identifier, Proficiency Name, and Number of Pledges." if len(args) > 3: return "Specify A Business Identifier, Proficiency Name, and Number of Pledges." business_name = args[0] from model.employer import Employer this_employer = Employer.get_by_key_name(business_name) if not this_employer: return "employer does not exist" proficiency_name = args[1] from model.proficiency import Proficiency #import string -- Capwords sucks, darnit. #this_proficiency = Proficiency.get_by_key_name(string.capwords(proficiency_name)) this_proficiency = Proficiency.get_by_key_name(proficiency_name) pledge_num = int(args[2]) from model.employer import AutoPledge new_pledge = AutoPledge(employer = this_employer, proficiency = this_proficiency, count = pledge_num) new_pledge.put() return encode(new_pledge)
def dump_raw_items(self, list_of_items, *response): return encode(list_of_items)
def SetItemModStatus(self, *args): # set moderation status for raw item this_item = db.get(args[0]) if args[1] == "false": this_item.moderated = False if args[1] == "true": this_item.moderated = True this_item.put() return encode(this_item)
def GetTopicsForProficiency(self, *args): topics = [] this_subject = Proficiency.gql("WHERE name = :1 ORDER BY date DESC", args[0]) # try get_or_insert if Proficiency is key topics = ProficiencyTopic.gql("WHERE proficiency = :1 ORDER BY date DESC", this_subject.get().key()) try: return encode(topics.fetch(10)) # get 10 at a time...todo: lazy rpc-loader. except: return simplejson.dumps([])
def GetRawItemsForTopic(self, *args): raw_quiz_items = [] this_topic = ProficiencyTopic.gql("WHERE name = :1 ORDER BY date DESC", args[0]) #these_items = RawQuizItem().gql("WHERE topic = :1", this_topic.get()) try: return encode(this_topic.get().pages.get().raw_items.fetch(10)) # get 10 at a time...todo: lazy rpc-loader. except: return simplejson.dumps([])
def RetrieveProficiencies(self, *args): # todo: should be nested list of proficiencies and topics. return_proficiencies = [] #proficiencies = Proficiency.all() proficiencies = Proficiency.gql("WHERE name IN :1", ["Smart Grid", "Energy Efficiency", "Recovery.Gov", "Cars 2.0"]).fetch(1000) # remove after refactoring quiztaker return encode([proficiency.name for proficiency in proficiencies]) # temporary offset
def RetrieveTopics(self, *args): # todo: should be nested list of proficiencies and topics. return_topics = [] topics = ProficiencyTopic.all() return encode(topics.fetch(9))
def add_proficiency(self, *args): if len(args) < 3: return "Please give a name, status, and blurb" from model.proficiency import Proficiency save_entity = Proficiency.get_or_insert(key_name=args[0], name = args[0], status = args[1], blurb = args[2]) save_entity.put() return encode(save_entity)