Exemplo n.º 1
0
    def end(self):
        try:
            yield super().end()

            if not self.session_start_ok:
                return

            if self.user_state_at_exclusive_login:
                user = User(self.user_state_at_exclusive_login)
            else:
                user = self.handler.user
                yield user.sync('instances')

            is_teacher = (user.status == 'room')
            is_student = (user.status == 'seat')

            # Room Deassign Course
            # Leave seat
            yield self.end_room_usage(user, is_teacher, is_student)

            # User Deassign Course
            yield user.deassign_course(if_last_instance=is_teacher)

            # Decrease Instances
            # (can modify status and course_id)
            yield user.decrease_instances()

        except:
            raise
Exemplo n.º 2
0
def login() -> Any:
    """Login user"""
    # Handle already authenticated
    if current_user.is_authenticated:
        return redirect("/app")

    # Render template as default
    provider = request.args.get("provider", None)
    if provider is None:
        return render_template("login.html")

    # Handle login
    info: Dict = {}
    if provider == "azure":
        if not azure.authorized:
            return redirect(url_for("azure.login"))
        else:
            info = azure.get("/v1.0/me").json()
    else:
        pass

    if info:
        email = info["userPrincipalName"]
        user = User.query.filter_by(email=email).first()
        if user is None:
            user = User(email)

        user.authenticated = True
        db.session.add(user)
        db.session.commit()
        login_user(user, True)
        return redirect("/app")
    return redirect("/login")
Exemplo n.º 3
0
def sample_data(engine):
    session = sessionmaker(bind=engine)()
    session.add_all([
        User(external_id=1,
             name="Owner First",
             imported_at=datetime.datetime.now()),
        User(external_id=2,
             name="Owner second",
             imported_at=datetime.datetime.now()),
        User(external_id=3,
             name="owner THIRD",
             imported_at=datetime.datetime.now()),
    ])

    session.add_all([
        Repository(
            external_id=1,
            name="repos/repo",
            owner_id=1,
            languages="python",
            imported_at=datetime.datetime.now(),
        ),
        Repository(
            external_id=2,
            name="repos/repo_2",
            owner_id=2,
            languages="ruby",
            imported_at=datetime.datetime.now(),
        ),
        Repository(
            external_id=3,
            name="repos/repo_3",
            owner_id=3,
            languages="golang",
            imported_at=datetime.datetime.now(),
        ),
    ])
    session.commit()
    session.close()
Exemplo n.º 4
0
 def post(self):
     """Creates new user"""
     first_name, last_name, email, password, u_type = itemgetter(
         'first_name', 'last_name', 'email', 'password',
         'type')(request.json)
     user_object = User.query.filter_by(email=email).first()
     if user_object:
         return jsonify(message='Email is already in database!'), 400
     hashed_password = bcrypt.hashpw(password.encode('utf-8'),
                                     bcrypt.gensalt())
     new_user = User(first_name=first_name,
                     last_name=last_name,
                     email=email,
                     password=hashed_password.decode('utf-8'),
                     user_type=u_type)
     db.session.add(new_user)
     db.session.commit()
     return jsonify(message='User has been inserted!')
Exemplo n.º 5
0
def orsen():
	global manwal_kawnt, storyId, endstory, endstorygen, story_list, turn_count, userid, username, secret_code
	
	#print(json.dumps(request.get_json()))
	requestJson = request.get_json()
	
	focus = requestJson["inputs"][0]#["rawInputs"][0]["query"]
	#print(focus["intent"])
    
    #FOR FILES - OPEN
	dm_fileWriter = open(dialogueLogs+ "/" + date+".txt", "a")
	convo_fileWriter = open(convo_path+ "/" + date+".txt", "a")
	ie_fileWriter = open(information_path+ "/" + date+".txt", "a")
	
	#When the app invocation starts, create storyid and greet the user and reset reprompt count
	if focus["intent"] == "actions.intent.MAIN":
		storyId = storyId + 1
		print("STORY ID ",storyId)
		new_world(storyId)
		#reset reprompt count
		manwal_kawnt = 0
		turn_count = 5 #change back to 0
		story_list = []
		#greet user (app.ask)
		data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Hi! What's your name?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
        
		#FOR 
		convo_fileWriter.write(date + "\n")
		ie_fileWriter.write(date + "\n")
		dm_fileWriter.write(date + "\n")
		convo_fileWriter.write("ORSEN: Hi! What's your name?" + "\n")

	elif focus["intent"] == "actions.intent.GIVE_IDEA_ORSEN":
		data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Okay, I will give you a hint"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
        
        #FOR FILES
		convo_fileWriter.write("ORSEN: Okay, I will give you a hint" + "\n")
	
	
	#When there is no input: ask the user (prompt from model) until maximum count is reached 
	elif focus["intent"] == "actions.intent.NO_INPUT":
		#increment reprompt count
		manwal_kawnt = manwal_kawnt + 1
		#app termination when maximum reprompt count is reached
		if manwal_kawnt == MAKSIMUM_KAWNT:
			data = {"expectUserResponse": False, "finalResponse": {"speechResponse": {"textToSpeech": "Okay. Goodbye"}}}
            
			#FOR FILES - CLOSE
			convo_fileWriter.write("ORSEN: Okay. Goodbye" + "\n")
			convo_fileWriter.close()
			ie_fileWriter.write("~~~ Story Ends Because of No Input ~~~" + "\n")
			ie_fileWriter.close()


			world = server.get_world(storyId)
			dm_fileWriter.write("\n\n")
			dm_fileWriter.write("---DIALOGUE MOVE COUNTS--- \n")
			dm_fileWriter.write("FEEdBACK COUNTS: "+ str(world.feedback_count) + "\n")
			dm_fileWriter.write("GENERAL COUNTS: "+ str(world.general_pump_count) + "\n")
			dm_fileWriter.write("SPECIFIC COUNTS: " + str(world.specific_pump_count) + "\n")
			dm_fileWriter.write("PROMPT COUNTS: " + str(world.prompt_count) + "\n")
			dm_fileWriter.write("HINT COUNTS: " + str(world.hint_count) + "\n")
			dm_fileWriter.write("SUGGEST COUNTS: " + str(world.suggest_count) + "\n")
			dm_fileWriter.write("FOLLOWUP1 COUNTS: " + str(world.followup1_count) + "\n")
			dm_fileWriter.write("FOLLOWUP2 COUNTS: " + str(world.followup2_count) + "\n")

			dm_fileWriter.write("---COMBINATION DIALOGUE MOVE COUNTS--- \n")
			dm_fileWriter.write("F + General: "+ str(world.feedback_general_count) + "\n")
			dm_fileWriter.write("F + Specific: "+ str(world.feedback_specific_count) + "\n")
			dm_fileWriter.write("F + Hinting: "+ str(world.feedback_hint_count) + "\n")
			dm_fileWriter.write("F + Suggesting: "+ str(world.feedback_suggest_count) + "\n")

			dm_fileWriter.write("---SUGGESTION YES/NO--- \n")
			dm_fileWriter.write("Yes: "+ str(world.yes) + "\n")
			dm_fileWriter.write("No: "+ str(world.no) + "\n")

			dm_fileWriter.write("---Follow Up1 Don'tLike/Wrong--- \n")
			dm_fileWriter.write("Don't Like: "+ str(world.dontLike) + "\n")
			dm_fileWriter.write("Wrong: "+ str(world.wrong) + "\n")

			dm_fileWriter.write("---Follow Up2 in/not--- \n")
			dm_fileWriter.write("In Choices: "+ str(world.inChoices) + "\n")
			dm_fileWriter.write("None of the Above: "+ str(world.notInChoices) + "\n")

			dm_fileWriter.write("---GLOBAL + LOCAL CONCEPTS --- \n")
			dm_fileWriter.write("GLOBAL CONCEPT LIST: " + str(world.global_concept_list) + "\n")
			dm_fileWriter.write("LENGTH GLOBAL CONCEPT LIST: " + str(len(world.global_concept_list)) + "\n")
			dm_fileWriter.write("LOCAL CONCEPT LIST: " + str(world.local_concept_list) + "\n")
			dm_fileWriter.write("LENGTH LOCAL CONCEPT LIST: " + str(len(world.local_concept_list)) + "\n")
			dm_fileWriter.write("END OF SESSION")

			dm_fileWriter.close()
		#reprompt user
		else:
			#get the reprompt
			retrieved = retrieve_output("", storyId, userid, dm_fileWriter)
			
			if retrieved.type_num == MOVE_HINT:
				extract_info(userid, retrieved.get_string_response())
	
			output_reply = retrieved.get_string_response()
			#reprompt user
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":""+output_reply+""}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
	
	elif turn_count == 1:
		rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
		turn_count = turn_count + 1
		username = str(rawTextQuery).split()
		username = username[len(username)-1].lower()
		convo_fileWriter.write("CHILD: My name is " + username + "\n")
		ie_fileWriter.write("Child name is " + username + "\n")
		data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Do we have a secret code?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
		
	elif turn_count == 2:
		rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
		if "yes" in str(rawTextQuery).lower():
			turn_count = turn_count + 2
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"I see, can you tell me what it is?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
		else:
			turn_count = turn_count + 1
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"I see, let's make one then. So what will it be?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
		
	elif turn_count == 3:
		rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
		if str(rawTextQuery) != "":
			secret_code = str(rawTextQuery).split()
			secret_code = secret_code[len(secret_code)-1].lower()
			turn_count = turn_count + 2
			# add to DB
			user = User.User(-1, username, secret_code)
			if DBO_User.get_user_id(username, secret_code) == -1:
				DBO_User.add_user(user)
			# get user id
			userid = DBO_User.get_user_id(username, secret_code)
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Yey, a new friend! Let's make a story. You go first " + username + "."}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}

	elif turn_count == 4:
		rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
		secret_code = str(rawTextQuery).split()
		secret_code = secret_code[len(secret_code)-1].lower()
		# check if username and secret code match in db

		userid = DBO_User.get_user_id(username, secret_code)
		
		if userid != -1:
			turn_count = turn_count + 1
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Oh, you remembered " + username + "! Okay, let's make a story then. You start!"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
		else:
			print("try again")
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Hmm, I don't think that was our secret code. Why don't you give it another try " + username + "?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}

	#When there is input, simply pass to model and get reply
	else:
		rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
	
		manwal_kawnt =0
		# userId = requestJson["user"]["userId"] # some really long id
		data = {}
		genstory = ""
	
		#print(rawTextQuery + " ["+userId+"]")

		if endstory:
			rawTextQuery = requestJson["inputs"][0]["rawInputs"][0]["query"]
			#If user wants to create another story, create new story and reset reprompt counts
			# if user wants to hear the whole story
			if (not endstorygen) and (rawTextQuery == "yes" or rawTextQuery == "yes." or rawTextQuery == "sure" or rawTextQuery == "sure." or rawTextQuery == "yeah" or rawTextQuery == "yeah."):
				#(edit-addhearstory-p2)swapped the contents of first and this condition
				output_reply = generate_collated_story(server.get_world(storyId))
				print("-----======= GENERATED STORY =======------")
				print(output_reply)
				data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":""+output_reply+""+". Do you want to create another story?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
				endstorygen = True
                
				#FOR FILES
				convo_fileWriter.write("CHILD: "+ rawTextQuery + "\n")
				convo_fileWriter.write("ORSEN: "+ output_reply + "Do you want to create another story?" + "\n")
			
			# user does not want to hear the full story
			elif not endstorygen:
				#(edit-addhearstory-p1) changed prompt from 'hear story' to 'create story'
				data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Okay. Do you want to create another story?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
				endstorygen = True
                
				#FOR FILES
				convo_fileWriter.write("CHILD: "+ rawTextQuery + "\n")
				convo_fileWriter.write("ORSEN: Okay. Do you want to create another story?" + "\n")
				
			# user wants to create a new story
			elif endstorygen and (rawTextQuery == "yes" or rawTextQuery == "yes." or rawTextQuery == "sure" or rawTextQuery == "sure." or rawTextQuery == "yeah" or rawTextQuery == "yeah."):
				#(edit-addhearstory-p2) swapped the contents of first and this condition
				data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Okay then, Let's create a story. You start"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
				manwal_kawnt = 0
				storyId = storyId + 1
				print("STORY ID ",storyId)
				new_world(storyId)
				endstorygen = False
				endstory = False
				story_list = []
				turn_count = 0
                
				#FOR FILES
				convo_fileWriter.write("CHILD: "+ rawTextQuery + "\n")
				convo_fileWriter.write("ORSEN: Okay then, Let's create a story. You start" + "\n")
				
			#If the user does not want to create a new story 
			else:
				#inserted, generatestory
				data = {"expectUserResponse": False, "finalResponse": {"speechResponse": {"textToSpeech": "Thank you. Goodbye"}}}
				endstorygen = False
				endstory = False
				story_list = []
				turn_count = 0
                
				#FOR FILES - CLOSE
				convo_fileWriter.write("CHILD: "+ rawTextQuery + "\n")
				convo_fileWriter.write("ORSEN: Thank you. Goodbye" + "\n")
				end = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
				convo_fileWriter.write(end)
				convo_fileWriter.close()

				ie_fileWriter.write("~~~ End Session ~~~")
				ie_fileWriter.write(end)
				ie_fileWriter.close()
				
		#when the user says they want to stop telling the story
		elif rawTextQuery.lower() == "bye" or rawTextQuery.lower() == "the end" or rawTextQuery.lower() == "the end.":
			#(edit-addhearstory-p1) changed the prompt from 'create another story' to 'hear full story'
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":"Wow. Thanks for the story. Do you want to hear the full story?"}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
			endstory = True
            
			#FOR FILES
			convo_fileWriter.write("CHILD: "+ rawTextQuery + "\n")
			convo_fileWriter.write("ORSEN: Wow. Thanks for the story. Do you want to hear the full story?" + "\n")
            
		else:
			result = None
			story_list.append(rawTextQuery)
			# if the reply is a story, then extract info and add in story. If not, then don't add
			if getCategory(rawTextQuery) == CAT_STORY:
				# you can pass user id here
				story_list[len(story_list)-1] = extract_info(userid, story_list, ie_fileWriter)
				result = get_unkown_word()
			
			if result != None:
				output_reply = "I need help! Please use " + result + " in a sentence."

			else:
				#dialogue
				#get the dialogue regardless of type
				retrieved = retrieve_output(rawTextQuery, storyId, userid, dm_fileWriter)

				if retrieved.type_num == MOVE_HINT:
					extract_info(userid, retrieved.get_string_response(), ie_fileWriter)

				output_reply = retrieved.get_string_response()
				
			data = {"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":True,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"textToSpeech":""+output_reply+""}],"noInputPrompts":[{"textToSpeech":tts,"displayText":dt}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
	
			print("I: ", rawTextQuery)
			print("O: ", output_reply)

			convo_fileWriter.write("Child: " + rawTextQuery + "\n")
			convo_fileWriter.write("ORSEN: " + output_reply + "\n")
	
	
	#if expectedUserResponse is false, change storyId
	
	return jsonify(data)